The solution to this is to install noclamshell via brew or just get in the habit of disconnecting your mac first before closing the lid.
I noticed this because previously it was sleeping completly fine and the problems started only recently which is inline then I started using the dock.
The speed and reliability with which a Mac sleeps and wakes and how well it maintains battery is insanely good. My Windows laptop was more like a portable desktop, as I always had to plug it in and would walk around with the lid open rather than risk a sleep/wake attempt between meetings.
Also I have had this issue with Macbook Pro 15 (2019), so it can't be guaranteed every-time for any OS I guess; not sure of the reason though. To me closing the lid should take preference over everything.
My previous, older Mac wouldn't sleep at all for more than a few seconds unless I unplugged the external monitor.
The "modern standby" feature on macs is called power nap: https://support.apple.com/en-ie/guide/mac-help/mh40773/mac
It already has different behavior depending on whether it's on battery or mains.
You can turn it off but it's not the option that Linus mentioned. It's elsewhere: https://support.apple.com/en-ie/guide/mac-help/mh40774/mac
On Apple Silicon Macs, the machine is never going into that deep a sleep to wake up from (it's basically a huge iPhone, remember?) and Wake for network access is not for Wake on LAN but rather if you want it to keep WiFi running to get push notifications etc while in "sleep" (the description under it in Settings even says it's for iMessage and iCloud updates).
Marcan has talked about Apple Silicon sleep states wrt to implementing it in Asahi Linux and IIRC they never put the machine to sleep, they just stop all the processes and hardware like the display and let the CPU idle normally (which it's extremely efficient at)