In general, the reason for users looking for a way to stop the Laptop from going in to sleep mode when the Lid is closed is to avoid the possibility of the Laptop in Sleep Mode being placed in its case/carry bag.
When a Laptop computer in sleep mode is being carried around in its case, there is always the possibility of the computer being damaged due to build-up of heat. This can happen, if the computer wakes up from sleep due to a jostle or movement and starts generating heat faster than normal due to its confined case.
Prevent Laptop from Sleeping When Lid Is Closed
While the default Setting on a Windows computer is to go into Sleep Mode when the Lid is closed, it can also 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 “Do Nothing” option; which prevents the computer from going to sleep; if it was switched ON prior to its Lid being closed. The other options that are available for selection in Windows Power Settings are “Hibernate” and “Shut Down”.
1. Prevent Laptop Going to Sleep When Lid Is Closed
As mentioned above, you can prevent the Laptop from going into sleep mode when 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 a confined 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 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 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.

While the Hibernation mode in Windows is designed to be “zero-power” state, it is still possible for a laptop in Hibernate mode to wake up; if it gets triggered by scheduled tasks, software updates or a mouse click.
Hence, you still need to make sure that the computer is completely powered-off; before it is being put in its case or the carry bag.