(How) can I prevent pasta water from boiling over with the lid closed?
You can use a larger pot. I always use my 12 qt stock pot to boil pasta in. I fill it anywhere from 1/3 to 2/3 full and have no problems with boil over. I too always use it with the lid on. Granted, you're going to use more energy to heat a larger quantity of water, but meh. I'd bet that your refrigerator and A/C use gobs more energy than your range.

As to why it happens? I'm speculating here, but maybe it's the back pressure on the foam bubbles when the lid is on. With the lid off the bubbles can expand rapidly, and break. With the lid on, there is slight back pressure which could restrict the bubbles ability to expand as quickly.