I'm curious if it had any good historical reason, that's why I'm asking.
I can handle the question about long robes. The Guardian refers to a study conducted by researchers from Harvard and Tel-Aviv Universities. The study focused specifically on why black robes i particular weren't a disadvantage in the heat but does offer an explanation for how robes work.
Bedouins' robes, the scientists noted, are worn loose. Inside, the cooling happens by convection – either through a bellows action, as the robes flow in the wind, or by a chimney sort of effect, as air rises between robe and skin.
As for why loose robes are better than seemingly cooler less concealing clothes.
In this NPR article, a physiology professor at Loughborough says that
...in terms of the heat loss, the naked person is best able to lose heat." That's only if the sun's not shining. If the sun's out, you need clothing to protect your skin from burning. "So then you have to find a balance with a certain amount of clothing coverage," Havenith says, "without the clothing actually hampering the sweat evaporation."
This formed the logic behind traditional Arab dress, which then got culturally exported to a greater or lesser extent across the Dar-al-Islam.
I will leave the reasons behind why women should or should not be covered in public to someone more equipped to answer that part of your question.