The HIG have no single rule that states when applications should quit. The guideline is: if the application cannot do anything sensible for the user when the main window is closed, then it should quit. Closing the last window is just one possible reason why an application should quit, but not the only one. Safari should not quit, because the user might want to open another window. System Preferences should quit, because the main window is the sole functionality of the application. Activity Monitor should not quit despite having just one main window, because the user might want to leave the program running so that it can gather statistics over a period of time.
There are obviously some edge cases. Mail, for instance, should probably quit, because the user can assume that it will fetch new emails in the background just like Contacts and Calendar do. It does not, because Apple has not built Mail that way. On the other hand, Mail should stay open, because the user might want to compose another email quickly. iTunes should probably quit, but then the user cannot use the play controls on the keyboard anymore. It is a balancing act between user expectations and functionality.
There are of course many examples where Apple actually flaunted the guidelines. The new app designs in iOS 10 for instance are a concurrent example. On the Mac, it was particularly annoying with iTunes in the past. Even the aesthetics: they had this really odd, bright gradient in the toolbar at some point, rather than the flat grey colour. In one version they even placed the window buttons vertically. They used these blue–grey, opaque scrollbar handles instead of the ‘lickable’ toothpaste ones. These were so omnipresent there that many people here actually thought that Apple would change the Aqua design itself to match them, and called it ‘marble theme’.