A question similar to yours was put to the Standing Committee for Issuing Fatwas, headed by Shaykh Ibn Baaz (may Allaah have mercy on him). It reads as follows:
I am a student in the faculty of medicine and next year we will be covering the subject of gynaecology and obstetrics. I want to ask the following:
(a) Is it permissible for me to attend the practical classes in which women’s bodies may be uncovered?
(b) Is it permissible for a male doctor to specialize in gynaecology and obstetrics, or is this only for female doctors?
They replied: If there is a sufficient number of female specialists in gynaecology and obstetrics, then it should be limited to them and it is not permissible for you to study it, or to look at the ‘awrahs of women when training, whether that is examining them or doing surgery on them. But if there are not enough women specializing in gynaecology to do what is essential in this field, and there is a need for Muslims to specialize in it, then it is permissible for you to study it and you have a concession allowing you to see whatever you need to see to examine women and do operations. End quote.
Fataawa al-Lajnah al-Daa’imah (12/175)
And Allaah knows best.