`-displayfd` always select display :0 even if in use when X launched as root
At X launch, when
-displayfd is passed as a command-line argument but no explicit display directive is, the automatic display selection is triggered. It works by trying to create and bind sockets for each display number in turn, starting from :0. For UNIX domain sockets, the code in xtrans first unlinks the well-known file for the display to try (e.g.,
/tmp/.X11-unix/X0 for :0) and then bind the just-created socket to the file again. If X is launched as root (or installed setuid), unlinking always work, and :0 is always selected, making a pre-existing session stale (and even worse, e.g., programs then launched by this session are displayed in the new session!).
This is what, e.g., the SDDM session manager triggers that: It passes "-displayfd", and no display directive, relying on the server to do display assignmnent, which it doesn't do correctly.