Question: Religions, in some countries, encounter university students and inform them that in the university they are mixed with women—so is the mixing of men with women in universities and schools unlawful, with the knowledge that there occurs between male students and female students the exchange of lustful glances, and likewise the professors; and there are also among them some who flirt, and they exchange speech between them.
And if this is unlawful, then is it valid for a religious student to continue his study, and lower his gaze, and restrain his tongue? Or is it not valid?
The answer—and Allah is the One Who grants success: It is not permissible for the believer to attend gatherings of wrongdoing, even if he is safe regarding himself from falling into wrongdoing—except that he attend those gatherings for the purpose of forbidding the wrongdoing and changing it; and if the matter is as in the question, then it is not permissible for the believer to continue the study.
Source: Min Thimār al-ʿIlm wa al-Ḥikmah vol.3