How does WSL manage GUI apps? Why do some work when others don't?

To understand what's going on, you have to make the distinction between "Windows GUI Apps" and "Linux (X) GUI Apps". Everything that you mention that opens is a Windows application.

It's important to note that this answer is only for the current released version of WSL. Later this year, WSLg is scheduled to be released with the 21H2 update of Windows 10. This will add the ability to run Linux GUI applications. As you mention a "workaround" in your question, you are already aware that WSL does not currently include this capability, unless you are running a Windows Insider/Preview version, or if you have manually installed a separate X Server and configured it (as mentioned in the "workaround").

While you would normally expect that you would have to start a Windows app in WSL using the .exe version (and you'd be correct), there are a few exceptions.

For the code . example that you mention, Microsoft specifically includes a shell script in the VSCode download and places it in the Windows PATH. Because you are calling code instead of code.exe, this shell script is being run. You can take a look at it with view "$(which code)". This script, among other things, ends up calling the Windows .exe version.

If you are curious why Windows executables (.exe's) work in WSL, please see this very good answer on the topic.

As for Jupyter notebooks, it is specifically launching a URL. Python includes a webbrowser library that allows it to launch a browser with a URL. You can try it out by launching python3 and then entering the following commands:

>> import webbrowser
>> webbrowser.open("https://superuser.com/q/1654716/1210833")
true

Note that this only works out of the box on the Ubuntu distribution on WSL, and perhaps some others that have provided the proper hooks. For example, in OpenSuse, it does not work by default:

>> import webbrowser
>> webbrowser.open("https://superuser.com/q/1654716/1210833")
false

However, on other distributions, you can simply export the BROWSER environment variable. For example, I'm using the Vivaldi browser on Windows:

export BROWSER="/mnt/c/Program Files/Vivaldi/Application/vivaldi.exe"

After that, OpenSuse works the same as Ubuntu with the webbrowser.open call.

Ubuntu provides the wslu package by default on WSL. This includes wslview, to open the default app for a file (e.g. wslview payroll.pdf) and also the www-browser hook which is probably what Python is using when you launch your Jupyer notebook.