There are a number of different possibilities. On my Thinkpad BIOS is sending to APM, part of the kernel, that the lids been closed, take a nap.
On these generic Lapnotes (no kidding, that was the brand name), the boards are simple, when the lid is closed the screen shuts off with a mechanical switch, but the machine is still running normally.
On this Compaq I had, APM enablement meant all sorts of confusion as the BIOS was built to sleep the laptop whether the OS agreed or not, which of course meant as soon as it snoozed it crashed. I got into BIOS and turned it off...
Usually none of this has anything to do with X and is entirely APM or APIC, both kernel components, talking to the laptop's BIOS.