These are the sources i could find regarding gender segregation, and are usually given by fatwa_sites when asked about gender segregation.
The first source is Allah recommending the guest of Prophet (pbuh) to ask the wives of Prophet (pbuh) behind a Hijab(screen/barrier/partition) regarding any detail/information.
And when ye ask (his ladies) for anything ye want, ask them from before a screen: that makes for greater purity for your hearts and for theirs. [Al-Ahzab:53]
The second source is this hadith reported from Abu Hurayrah that the Prophet (pbuh) said (regarding rows of mosques) :
The best of the men’s rows is the first and the worst is the last, and the best of the women’s rows is the last and the worst in the first (Muslim).
Meaning the further the men and women the better it is, even in a masjid/mosque.
Thirdly The Prophet pbuh gender separating the entrance/exit of mosque as Ibn ‘Umar said "Allah’s Messenger (pbuh) said:
We should leave this door (of the mosque) for women.
So there is not any intermixing of the two genders while exiting/entering.
Abu Usayd, was once coming from the mosque when he heard the Prophet sallallaahu 'alayhi wa sallam addressing women due to him seeing that the men and women were walking very close to each other after having exited from the mosque:
“Stay back! You should not walk in the middle of the street, rather, walk to one of its sides.” Abu Usayd, may Allah be pleased with him, added: “Thereafter, the women would walk so close to the walls on the side of that street that their garments would scrape against it.” [Abu Daawood]
This means a distance should be kept between men and women.
Although the last three sources do not directly impose gender segregation.
Views on this segregation:
People have mixed views on this segregation:
You can see different fatwas supporting gender segregation: 1, 2, 3 and many more.
Islamqa shows some statistical analysis of people regarding freemixing:
What is the Islamic ruling on mixing as far as you know? The results were as follows:
76% of respondents said “It is not permitted.”
12% said, “It is permitted” – but moral, religious, etc. restrictions apply…
12% said, “I don’t know.”
If you had the choice between working in a mixed workplace and working in another where there was no mixing, which would you choose?
76% would choose the workplace where there was no mixing.
9% preferred the mixed workplace.
15% would accept any workplace which suited their specialties, regardless of whether it was mixed or not.
British-born Muslim author Ed Husain argues that rather than keeping sexual desires under check, gender segregation creates "pent-up sexual frustration which expressed itself in the unhealthiest ways," and leads young people to "see the opposite gender only as sex objects." While working in Saudi Arabia for seven months as an English teacher, the Arabic-speaking Husain was surprised to find that despite compulsory gender segregation and full hijab, Saudi men were much less modest and more predatory towards women than men in other countries he had lived. Despite the modest dress of his wife – who "out of respect for local custom, ... wore the long black abaya and covered her hair in a black scarf" – she was on two occasions "accosted by passing Saudi youths from their cars. ... In supermarkets I only had to be away from [my wife] for five minutes and Saudi men would hiss or whisper obscenities as they walked past." Discussions with local women at the British Council indicated that her experience was far from unique. There is also a strong viewpoint growing among Muslims arguing against gender segregation. In Saudi Arabia which is known to be among the most gender segregated countries in the world there are occasional signs that gender segregation laws are becoming less strict. Some Muslims argue that women served food for the prophet Muhammad and his companions arguing that this is evidence that gender segregation did not exist during the earlier times of Islam.
Also 15 Strong Proofs Why Men and Women Mixing Is Halal from CJ Ahmad (this person has some questionable views conflicting recognized osols)