*Sigh*: Heat dispersal.
Spacecraft get HOT. That heat has to be released or the crew/pilot/cargo will literally, eventually boil (and one source of that heat is the crew!). "But space is cold!" Yes, it is. It's also A VACUUM.
In an atmosphere (as on Earth), living things release heat by convection to the atmosphere (or, if water creatures, to the water). So to do mechanical devices. It's easy and cheap and practically automatic— indeed for many devices convection is a problem, and we want to keep it from happening (hence, YETI and Teva double-walled "insulated" coffee cups).
But in a vacuum, convection is impossible. The only way to release heat is via straight thermal radiation. You do this by creating large metal surfaces exposed to space, which lets the heat radiate away.
Now, look at the X-wing: It has massive weapons systems mounted on the ends of the struts, away from the fuselage. There should be no question that these produce enormous amounts of heat, not all of which is applied to the blast. The struts thus keep that heat from being applied to the fuselage (and crew), while providing broad surfaces to radiate the excess heat into space. When not in combat, the heat would not be generated, so the "foils" are closed, cutting the radiating surface area effectively in half (you don't want to radiate too much heat, either!).
And that's a perfectly rational and physical explanation for "wings" on a starfighter. (Though honestly the idea of a crewed "starfighter" is probably an unlikely development— drones would be better.)