Windows 8: How to Lock (not sleep) laptop on lid close?
There is no built in way to do this, but you could use LidLock for this purpose. It is a GUI tool which can help you what you want to achieve. You can also set it to start automatically with Windows start-up.
You can also set the timer for sleep/hibernate after locking the laptop.
You can read more about this on this article.
Using Run from the start menu, execute
Right click > New > DWORD (32 bits)
Rename it to
Select it > Right click > Change value to
Go to the Power Options settings page and change the lid close action to sleep.
— Source: Microsoft Answers - Lock computer on lid close?
I wrote an alternative to the LidLock application suggested in other answers, called LapLock. What it does is simply listen for the lid close event and lock the computer when the event fires. Compared to LidLock mine is very bare-bones (it doesn't even have a UI), but also more lightweight.