How to make a Macbook Pro lock and not sleep when connected to power?
This can be done in Energy Saver:


Open System Preferences 
Go to Energy Saver
Select Power Adapter
Check/mark the "Prevent computer from sleeping automatically when the display is off" option
[Optional] Uncheck "Put hard disks to sleep when possible".