When my external display is on, my Mac thinks it's off. When it's off, on

Solution 1:

Restart you Mac and try resetting the PRAM:

Hold down the ++R+P keys until you hear the start up chime two times.

Solution 2:

You can also try to reset the 'System Management Controller (SMC)' as described here: http://support.apple.com/kb/HT3964

Take note of the following description:

"After performing normal troubleshooting, these symptoms may indicate that an SMC reset may be necessary: [...]

Video

A computer that supports target display mode does not switch into or out of target display mode as expected.

A computer that supports target display mode switches into or out of target display mode at unexpected times."