Change Lid Options in Windows
You can change this behavior in Windows 10 and Windows 11 from the Control Panel. The quickest way to do this is to open the Start menu and search "lid" and select the Choose what closing the lid does entry.
The Control Panel will open and a new menu will appear within the Power Options settings. From here, you can see options for when you press the power button or sleep button. What we want to focus on is the When I close the lid section, where you can set what happens when the laptop is on battery power and is plugged in.
The drop-down menu offers four options—Sleep, Hibernate, Shut down, and Do Nothing. For our purposes here, you should set it to Do Nothing when the computer is plugged in. This allows the closed laptop to continue functioning while it is hooked up to a power source, so you can use it as a desktop alternative without having to deal with the device itself.