Both behaviors have been common/"correct" as long as I remember. Single window apps such as System Preferences, Disk Utility, etc. don't meaningfully exist without their window and as such they quit when the window closes. Multi-window apps e.g. web browsers, word processors have the "usual" macOS behavior where they can remain running without a window open.
Importantly, both behaviors are correct under the appropriate circumstances (which you described). It’s not random or discretionary.