Reference: Majmoo’ Fataawa wa Rasaa.il Muhammad ibn Saalih al-‘Uthaymeen – Volume 13, Fatwa No.412
Question: Sometimes due to the extreme crowds in the Haram (al-Masjid al-Haraam, Makkah) the men [end up] praying behind the women or [you find] a man praying beside a woman, so is that correct?
And if a woman or women came and prayed beside him, then what should he do?
Response: If a man prayed behind the row of the women, then there is no harm in that as the jurists have stated, because the people are in need of doing so [when the need arises especially in the Haram area]. However, if a woman prayed beside him and he feared the fitnah [of her praying beside him] then he should indicate [with his hand] she move away from him if he came and prayed there before she did. If, however, she came before him, then he should move to another place. And if a woman or women came and prayed beside him whilst he is praying, then he should indicate to them (with his hand) to move away from him.