All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
The usual mixing between men and women in many universities today is something reprehensible, and it is the cause of many corruptions and evils. In case of an urgent need to enroll in these universities, such as the absence of alternative universities in which there is no mixing, then there is nothing wrong with you joining the university and studying there, with the obligation of observing the Sharee’ah guidelines, such as adhering to the Islamic Hijab, not being alone with any man in one place, not mixing with them [men] by touching or shaking hands and the like, and not being soft in speech with them.
The forbidden mixing: It is the gathering of men with women, with the presence of Sharee’ah prohibitions, such as not wearing Hijab, being alone with men, being soft in speech with men, and the like, which violates the Sharia conditions. As for the mere presence of men and women in one place without breach to the rules of Sharia, it is not forbidden for you.
The Encyclopedia of Fiqh (jurisprudence) reads: “The ruling on the mixing of men with women differs according to whether or not it agrees with the rules of Sharia. Mixing is prohibited if:
A. Being alone with a non-mahram woman and looking lustfully at her.
B. Women not wearing Hijab and not being modestly dressed.
C. Playful amusement and body touching (between men and women).
It is permissible for women to mix with men if there is a legitimate need with observance of the rules of Sharia. It is for this reason that it is permissible for a woman to go out to pray in congregation.” [End of quote]
As for whether your study of gynecology is a communal obligation on you if there are female doctors, the answer is no. If the communal obligation is done by some, it is waived from others. Therefore, if there are women physicians who meet the needs of women in this regard, then it is not obligatory for others to specialize in gynecology.
Allah knows best.