Praise be to Allah.
Before I discuss this matter, I would like to explain that there can never be any contradiction between an unambiguous statement of the Qur’aan and reality. If there appears to be a contradiction with reality, it is either because what we think is reality is a baseless claim, or the (text of) the Qur’aan is not opposed to this reality in a clear and definite manner. The unambiguous statements of the Qur’aan and the facts of reality are both definitive, and two definitive things can never contradict one another.
Based on the above, it may be said that now they (doctors) are able, through the use of precise machines, to discover what is in the wombs and to find out whether it is male or female. If what is said is false, then there is no point in discussing it. If it is true, then it does not contradict the aayah, because the aayah is referring to a matter of the unseen, which has to do with the knowledge of Allaah about these five matters. The matters of the unseen as far as the foetus are concerned are: how long he will remain in his mother’s womb, his life, his deeds, his provision, whether he is doomed (destined for Hell) or blessed (destined for Paradise), and – before it is fully formed – whether it will be male or female. But after it has been fully formed, knowledge of whether it is male or female is no longer the matter of the unseen, because once it has been fully formed it becomes the matter of the visible world, but it remains within the three layers of darkness which, if they were removed, it would be known what it is. It is not far-fetched to think that among the things that Allaah has created are powerful rays which can penetrate these layers of darkness so that it may become clear whether the foetus is male or female. The aayah does not clearly refer to knowledge of whether the foetus is male or female, and the Sunnah does not refer to that either.
With regard to what the questioner refers to, that Ibn Jareer quoted from Mujaahid that a man asked the Prophet (peace and blessings of Allaah be upon him) what his wife would give birth to, and Allaah revealed this aayah, this narration is munqati’ (interrupted), because Mujaahid (may Allaah have mercy on him) was one of the Taabi’een.
The tafseer of Qutaadah (may Allaah have mercy on him) may be interpreted as meaning that Allaah Alone has knowledge of that so long as it has not yet been fully formed. But once the foetus is fully formed, then others may have knowledge of it. Ibn Katheer (may Allaah have mercy on him) said in his tafseer of the aayah from Soorat Luqmaan: “No one knows what Allaah wants to create in the wombs apart from Him, but once He decrees that it should be male or female, doomed or blessed, the angels who are appointed in charge of it know that, and whoever else He wills among His creation.”
With regard to your question about what may make the general meaning of this aayah (“what is in the wombs”) more specific, we say that if the aayah was speaking about being male or female after the foetus is fully formed, then that which would make it more specific would be tangible facts. The scholars have mentioned the principles of making the general meanings of the Qur’aan and Sunnah more specific, which are a text, ijmaa’ (scholarly consensus), qiyaas (analogy), tangible facts or reason. Their comments on this matter are well known.
But since the aayah does not refer to after the foetus is fully formed, but rather it refers to before that time, there is nothing in it that would contradict the idea of knowing whether the foetus is male or female.
Praise be to Allaah, there is not, and never will be, anything in reality that contradicts the unambiguous statements of the Qur’aan. The accusations made by the enemies of the Muslims against the Qur’aan, that things happen which outwardly appear to contradict the Qur’aan, arise from their misunderstanding of the Book of Allaah which stems from their bad intentions. But the committed Muslims and scholars have enough knowledge to discover the truth which will refute the specious arguments of these people. Praise and blessings be to Allaah.
With regard to this matter, people may be one of two extremes, or a middle group.
One extreme is to adhere to the apparent meaning of Qur’aanic verses which are not unambiguous, and to reject any certain facts that go against it. Such people either expose themselves to criticism, or they expose the Qur’aan to criticism, because their view contradicts the certain realities of everyday life.
The other extreme is to turn away from that which is indicated by the Qur’aan and to adopt a purely materialistic approach. Thus one becomes a heretic.
The middle path is to accept both the indications of the Qur’aan and the facts of reality. These people know that both of them are true, and that the unambiguous statements of the Qur’aan cannot contradict something that is well known and visible. They combine acceptance of the transmitted texts with reason, thus keeping their religious commitment and their intellect safe and sound. Allaah guides those who believe to the truth of that wherein they differ, and Allaah guides whom He wills to a Straight Path (cf. al-Baqarah 2:213).
May Allaah help our believing brothers to achieve that, and may He cause us to be guided and to guide others, and make us righteous leaders. My strength is only in Allaah, in Him I put my trust and to Him I turn in repentance.