In general, the reason for users looking for a way to stop the Laptop from going to sleep when its Lid is closed is to avoid the possibility of the Laptop in Sleep Mode being placed in its case or carry bag.
When a Laptop in Sleep Mode is carried around in its case, there is always the possibility of the Laptop waking up and being damaged due to build-up of heat.
This can happen, if the Laptop wakes up from sleep mode due to a jostle or movement and starts generating heat faster than normal due to its confined case.
Stop Laptop Going to Sleep When Lid Is Closed
While the default Setting on a Windows Laptop is to go into Sleep Mode when the Lid is closed, it can be configured not to go in Sleep Mode by selecting other options that are available for the Lid Closing action in Windows.
For example, you can select the option to “Do Nothing”, which prevents the computer from going to sleep, if it was switched ON prior to the Lid being closed.
Similarly, Windows operating system provides the option to make the computer to go into Hibernate Mode or completely Shut-down; when the Lid is closed.
1. Prevent Laptop Going to Sleep When Lid Is Closed
As mentioned above, you can prevent your Laptop from going into sleep mode when its Lid is closed by selecting the option to “Do Nothing” when the Lid is closed.
1. Go to Settings > System > click on Power & Battery tab in the right-pane.
2. On the next screen, open Lid & Power Button Controls tab and select Do Nothing option for “Closing the Lid Will Make My PC” entry in the Battery section.

After this setting, it is really important that you get into the habit of shutting down the Laptop, before putting it in its case or carry bag.
A switched ON Laptop being carried around in its case is even more dangerous than a Laptop in Sleep Mode being carried around in its carry bag or case.
2. Shut Down Laptop When Lid Is Closed
You can totally rule out the possibility of a switched ON Laptop being carried around in its confined case by making the Laptop to Shut-down, when its Lid is closed.
1. Go to Settings > System > click on Power & Battery tab in the right-pane.
2. On the next screen, open Lid & Power Button Controls tab and select the Shut-down option for “Lid Closing Action” in Battery section.

This setting ensures that the Laptop is totally powered off, even if you forget to shut-down the Laptop before putting it in the carry bag or the case.
3. Hibernate Laptop When Lid Is Closed
Another option that is available in Windows is to make the Laptop to go into Hibernate Mode, when the Lid is closed.
1. Go to Settings > System > click on Power & Battery tab in the right-pane.
2. On the next screen, open Lid & Power Button Controls tab and select the Hibernate option for the “Lid Closing Action” in Battery section.

The advantage of this option is that your computer remains shut down in its case and yet it is able to spring back to life, in the same state that it was in prior to being put in Hibernate Mode.