I keep hearing from scientists that gender segregation was quite a thing among cavemen. In fact the idea of wife working at home and man going out to work started with them.
While men hunted, women stayed in the cave looking after children. It has something to do with "protection".
Point to note There is no evidence of this.
But I do see that gender segregation existed in Egyptian kingdom of Pharaohs.
Some people nowadays seem to think that ancient Egyptian women lived in an almost ideal world of equality. This was not the case. They may have had more rights and independence than women in other ancient societies, but they were not treated as equals by men. Throughout history they had little direct influence on public affairs. Their choice of profession was limited mostly to that of mistress of the house, though some became priestesses, others entertainers and a small handful even came to rule the country, be it as regent or as pharaoh. But the life of the ordinary ancient Egyptian woman was restricted to doing household chores, though one should not forget that the options the average ancient Egyptian man had were barely more numerous.http//www.reshafim.org.il/ad/egypt/people/couples.htm
Perhaps when Muslims came to Egypt, they were influenced by these segregation customs. This also applies to Byzantine society
A woman living in the age of Byzantium spent the greater part of her life in her home. We read, for instance, in Kekavmenos' s "Strategikon" "Keep your daughters as prisoners, confined and inconspicuous". A woman was invariably accompanied whenever she left her house to go to church, attend a festivity, visit the baths, or call on her relations -- the sole activities of a woman outside her own home that were socially acceptable.
Moreover, it was not proper for a woman to sit at table with men, unless they were close relatives, such as her father, husband, or brothers. Most often she would eat in a separate room, just as she would spend her days in rooms apart from the menfolk. She learnt all about household matters from a very early age; her education, in contrast, was usually limited to reading and writing. Very few women acquired a wider learning.
http//www.macedonian-heritage.gr/HellenicMacedonia/en/D2.5.html