Meanwhile I have researched this further. The pointer with systemd by Nicholas was spot on. Several ways seem to exist to mitigate the issue:
1. logind.conf
/etc/systemd/logind.conf and friends contain three relevant settings:
KillUserProcesses= (if yes a logoff will cause processes within the scope of the systemd-logind.service(8) session to be killed.
KillOnlyUsers= will allow to limit the list of users for which the above setting applies (space-separated list, e.g. adam eve joe jane).
KillExcludeUsers= is the opposite of the previous setting an makes users exempt from the effect of KillUserProcesses=yes.
So one could set KillUserProcesses=no or only include user gdm in KillOnlyUsers (if using GNOME) or list the users to be exempt from process killing on login session teardown via KillExcludeUsers.
You can see sessions with loginctl list-sessions.
2. loginctl enable-linger username
You can enable lingering for the current session by executing loginctl(1) as follows within the session scope (obviously replace username for the actual user name or $(whoami)):
loginctl enable-linger username
The clue can be found from the logind.conf(5) manual page:
In addition to session processes, user process may run under the user manager unit user@.service. Depending on the linger settings, this may allow users to run processes independent of their login sessions. See the description of enable-linger in loginctl(1).
3. systemd-run --scope --user command
The manual for logind.conf(5) contains the clue to this one:
Note that setting KillUserProcesses=yes will break tools like screen(1) and tmux(1), unless they are moved out of the session scope. See example in systemd-run(1).
And indeed looking at the manual for systemd-run(1) we find the following example:
Example 5. Start screen as a user service
$ systemd-run --scope --user screen Running scope as unit
run-r14b0047ab6df45bfb45e7786cc839e76.scope.
$ screen -ls There is a screen on:
492..laptop (Detached) 1 Socket in /var/run/screen/S-fatima.
This starts the screen process as a child of
the systemd --user process that was started by user@.service, in a
scope unit. A systemd.scope(5) unit is used instead of a
systemd.service(5) unit, because screen will exit when detaching from
the terminal, and a service unit would be terminated. Running screen
as a user unit has the advantage that it is not part of the session
scope. If KillUserProcesses=yes is configured in logind.conf(5), the
default, the session scope will be terminated when the user logs out
of that session.
Tested with
systemd 245 (245.4-4ubuntu3.2)
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid