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
regedit
.Navigate to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\Power
Right click > New > DWORD (32 bits)
Rename it to
AwayModeEnabled
Select it > Right click > Change value to
1
(Hexadecimal)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.