Apple's MacBook systems support a mode called "clamshell" which allows you to close the lid and continue using the system in a desktop configuration if you attach an external monitor and a keyboard. This mode is exceptionally useful for docking the system when at a work desk, but there may be times when the system will not properly enter clamshell mode, and instead stay in an extended desktop mode with the system's built-in display still active.
If this happens to you and your system will not fully enter clamshell mode, there are a couple of things you can try to clear the problem:
The system's detection of an external monitor and management of modes like clamshell is managed in hardware, for which settings are stored in the system's PRAM. Therefore, first you should try resetting the PRAM in hopes the system will properly load these modes. To do this, reboot the system and immediately hold the Option-Command-P-R keys all at once. With these keys depressed, the system will sound the boot chimes, then reset and sound them again continually. Allow this cycle to complete once; then release the keys and let the system boot normally.
Resetting the PRAM may change some settings like system volume and mouse pointer speed, but these should be reset from stored values in the OS once you load and use your system. If you have your OS installation on a secondary drive, then be sure after resetting the PRAM that you go to the "Startup Disk" system preferences and select your desired boot drive to ensure quicker boot times.
Disable extended desktop
In addition to resetting the PRAM, you can try disabling the option to use extended desktop altogether. By default the system will attempt to use both the external monitor and internal display in a dual-display setup; however, you can force the system to only use one display with a custom boot argument PRAM setting. To do this, open the Terminal utility and run the following command:
sudo nvram boot-args="iog=0x0"
Following this command, restart the system and your system will now either use the internal display, or only use an attached external display. To revert this setting, you can either reset the PRAM or run the following command to clear this value from the boot arguments (reboot for the change to take effect):
sudo nvram boot-args=""