How do you force OS X to re-detect displays?

Solution 1:

Go into System Preferences->Displays and when there (doesn't matter which tab) press the 'Option/ALT' key and you'll see 'Detect Displays' where the 'Gather Windows' button is (on 10.13.x) or simply in the lower right on 10.14.x (as this page doesn't have a 'Gather Windows' button.)

Solution 2:

Since at least OS X El Capitan (Version 11.x), you can force Detect Displays using Command-IncreaseBrightness (Cmd-F2 key on MacBook Pro, or Cmd-fn-F2 if you have function keys turned on).

I had a similar problem with my 13" MBP, where when I disconnected an external display it didn't detect that it should switch to the single, built-in display – regardless of whether the machine was already sleeping or the lid were quickly closed. Cmd-F2 worked for forcing the machine to detect that the only available display was the built-in one.

As a bonus, you can also toggle Display Mirroring using Cmd-DecreaseBrightness (Cmd-F1...). Hit it again to toggle back.

Hope this helps!