How to use MacBook with lid closed: Stop a closed Mac sleeping
Here's what you need to do if you want to stop your MacBook from sleeping when the lid is closed and even turn on your Mac without opening the lid.
Mac App Energy Saver Go To Battery Or Energy Saver Click Battery Or Energy Saver Time Machine System Preferences
Source: macworld.com