I've had this problem since I first bought the Macbook, and I'm still having this problem after messing around with certain settings.
I'm running macOS 12.5 (Monterey), a 14-inch 2021 model, with the Apple M1 Pro chip:
I have a wide AOC monitor, connected to my laptop via HDMI:
I disabled the power management options that would turn the display off – I set it to never. I also tried setting it to never, even when the macbook is unplugged and plugged. Whenever I connect my laptop to the monitor and close the lid, the laptop locks and the monitor provides a "No signal" message.
I also wiggle the mouse, and press keys on the keyboard in an attempt to wake the device, yet nothing seems to work.