When can they use ESC to close windows?
What you're seeing, namely, the behavior where the Escape key closes the window, is automatically built in to the NSPanel class, which is a subclass of NSWindow.

From Window Programming Guide &gt; How Panels Work:


  A panel is a special kind of window, typically serving an auxiliary
  function in an application. The NSPanel subclass of NSWindow adds
  a few special behaviors to windows in support of the role panels play:
  
  ...
  
  • If a panel is the key window and has a close button, it closes itself
  when the user presses the Escape key.


The preferences window (or panel) in many applications is implemented as an NSPanel: for example, Safari, Preview, Terminal, Console. The Fonts panel in Cocoa apps is implemented as an NSPanel. When you choose Safari > Safari Help, it actually launches an invisible background application, HelpViewer.app (/System/Library/CoreServices/HelpViewer.app), whose main window is implemented as a floating NSPanel. For these reasons, those panels will respond to the Escape key by closing the window. Standard general windows, which are instances of NSWindow, don't automatically get this behavior, as only panels are meant to behave that way.