MacBook Pro keeps crashing after using external monitor and then disconnecting it

I started using my 2013 MacBook Pro which is now running OS X Yosemite, and it very consistently crashes after (a) I use it with the lid closed and connected to an external monitor, and then (b) disconnect it from the external monitor and attempt to use it as a laptop again. It also crashes when I put it to sleep while still connected to the external monitor and then attempt to wake it up.

The link I shared comes the closest to describing the problem and a fix. Here’s Apple’s doc page on the pmset command.