Pop up headlights were to improve aerodynamics on cars with low front ends, without going down the old E-type Jag style of heavily recessed lights behind windshields. Someone later decided they looked cool and out them on every **** thing in the 80s that didn't need them.
I'm not a lore buff but I was under the impression the X-wing foils were just huge radiators for the guns, which is why you could snapshoot a single blast with them closed, but not continually fire. Also, when they were closed, the weapon power went to engines, hence the increased speed.
But again, I'm no buff for this background stuff. I'm just here for the pewpew.
The weapon power could go to engines without closing the S-foils and I think it's not just the cannons but engines and reactor also produce heat. I don't know if there is a canon reason for closing S-foils outside of combat, but maybe the inner surface is fragile or coated with some kind of layer that wears off because of spacedust or something, that's why they are meant to be closed when they aren't necessary (or when the ship isn't fully shielded)?
Edited by eMeM