Prevent macOS Messages.app from quitting when I close its window?

As far as I can see that's just another case of "Automatic Termination", similar to Preview, QuickTime Player, etc.

If you launch Terminal (from /Applications/Utilities/) and run the following command with Messages quit, Messages should stop terminating, when the window is closed:

defaults write com.apple.iChat NSDisableAutomaticTermination -bool yes

Then press enter.

To undo it again: defaults delete com.apple.iChat NSDisableAutomaticTermination