All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
It is not permitted for a woman to allow a male doctor (or even a female doctor) to see her `Awrah (parts of body that must be covered) only to find out the sex of the fetus. Uncovering the `Awrah is not permitted except for a compelling necessity. We believe that knowing the sex of a fetus is not a pressing need. The whole body of a woman in front of non-Mahram men is Awrah, while her Awrah in front of women is from the navel to the knee.
In addition to this, knowing the sex of a fetus does not bring any benefit for a woman; rather, it causes disappointment if the sex of fetus does not suit what she had expected. However, if it is possible to find out the sex of a fetus without uncovering the Awrah, or finding out the sex is needed for any medical purpose then it is permitted.
Allaah Knows best.