This is a quirk of Win32 and Unity Editor's windowing design.
When clicking on the close button of a non-foreground window, Windows does not initially send SC_CLOSE. The click is first interpreted as “activate this window”, not “press its close button”, but once the window is activated the click is further processed resulting in the close button receiving the click event.
This behavior occurs when the Editor's "main window" is open by itself with no other secondary windows.
However, if a secondary window is open, it is "owned" by the main window allowing it to appear at the top of the z-order, but this also changes the execution behavior of the mouse click. Activation is redirected to the secondary window (not main) so the mouse click isn't processed by the close button and the Editor remains open.
This behavior cannot be easily changed/fixed.