Al-jawab billahi at-taufeeq (the answer with Allah’s guidance)
Allah Ta’ala says
“Only Allah knows all what the wombs contain.”(Surah Luqmaan, Verse 34)
Man does not have the power to conclusively deter- mine the sex of the unborn baby.
In these times, however, medical doctors are able to ‘predict’ the sex of the baby-to-be, by means of X-Ray scan machinery.
Yes, it will be permissible to acquire partial knowledge of the womb after a fixed period of pregnancy elapses and the limbs etc. of the foetus are formed (but best not to).
If however, it is linked with ignorant ideas of gender preference, it would be disliked, and Haram when this would lead to unlawful abortion.
Also, the scan must be conducted by a female physician.
And Only Allah Ta’ala Knows Best.
Moulana Qamruz Zaman