Questions regarding how the foetus is created, what leads to it being male or female, and what leads to it resembling the father or the mother
Question

I read some hadiths about the formation of the foetus, which Ibn al-Qayyim quoted in his book at-Tibyan fi Aqsam al-Quran. He said that the Prophet (blessings and peace of Allah be upon him) said: “If the man’s water precedes the woman’s water, the foetus will be male, and if the woman’s water precedes the man’s water, then the foetus will be female…” Then he quoted another hadith, according to which the Prophet (blessings and peace of Allah be upon him) was asked from what man is created, and he (blessings and peace of Allah be upon him) replied: “From the water of the man and the woman together. From the man’s water the bones and sinews are created because it is thick and from the woman’s water the blood and flesh are created because it is soft.” Can you explain this idea in the light of these two hadiths?
Praise be to Allah.Firstly:
The second hadith quoted in the question is not sahih. Its wording, and the views of leading scholars concerning it, follow:
It was narrated that ‘Abdullah ibn Mas‘ud (may Allah be pleased with him) said: A Jewish man passed by the Messenger of Allah (blessings and peace of Allah be upon him) when he was talking to his companions. Quraysh said: O Jew, this man claims that he is a prophet. The Jewish man said: I shall ask him about something which no one knows except a prophet. So he came and sat down, then he said: O Muhammad, from what is man created? He said: “O Jew, [he is created] from both, from the water of the man and the water of the woman. As for the water of the man, it is thick and from it [come] the bones and sinews; as for the water of the woman, it is thin and from it [come] the flesh and blood.” The Jewish man stood up and said: This is what those who came before you said.
Narrated by Ahmad in his Musnad (7/437).
Shaykh Ahmad Shakir (may Allah have mercy on him) said:
Its isnad is weak (da‘if), because of the weakness of Husayn ibn al-Hasan, who is al-Ashqar. The hadith is in Majma‘ az-Zawa’id (8/241). And he said: It was narrated by Ahmad, at-Tabarani and al-Bazzar with two isnads. One of its isnads includes ‘Amir ibn Mudrik, whom Ibn Hibban regarded as trustworthy (thiqah), but others regarded him as weak. The rest of its narrators are trustworthy. The isnad of the group includes ‘Ata’ ibn as-Sa’ib, who at some point became confused and forgetful.
Musnad Ahmad, annotated by Shaykh Ahmad Shakir (6/199).
It was also classed as weak by the commentators on al-Musnad (7/437, ar-Risalah edn.), who said:
Its isnad is weak (da‘if) because of the weakness of Husayn ibn al-Hasan, who is al-Ashqar, and ‘Ata ibn as-Sa’ib, who became confused and forgetful at the end of his life. We have not come across anything to indicate whether Abu Kudaynah – who is Yahya ibn al-Muhallab – heard it from him before or after he became confused. Regarding ‘Abd ar-Rahman, the father of al-Qasim – who is the son of ‘Abdullah ibn Mas‘ud – it is not proven that he heard this hadith from his father, because he only heard a few hadiths from his father. End quote.
In addition to the isnad of this hadith being weak (da’if), there is also a problem with its text, as it says that the flesh of the foetus is formed from the water of the mother and its bones are formed from the water of the father. The apparent meaning of the religious texts is that the flesh and bones are formed from both waters together.
The commentators on al-Musnad narrated from Nur ad-Din Abu’l-Hasan as-Sindi (may Allah have mercy on him) that he said:
Regarding the words “as for the water of the woman, it is thin and from it [come] the flesh and blood,” I say: The apparent meaning of the Quran – namely the verse (interpretation of the meaning): {Then We made the sperm-drop into a clinging clot, and We made the clot into a lump [of flesh], and We made [from] the lump, bones, and We covered the bones with flesh; then We developed him into another creation} [al-Mu’minun 23:14] – indicates that the two waters together become bones. End quote.
Secondly: Regarding the creation of the foetus, whether it will be male or female, and whether it will resemble the father or the mother, all of these are issues for which there are indications in the Quran and Sunnah, and there is a difference of scholarly opinion regarding that. We may outline it in brief as follows:
-1-
Creation of the foetus
Allah, may He be exalted, says (interpretation of the meaning):
{So let man observe from what he was created.
He was created from a fluid, ejected,
Emerging from between the backbone and the ribs} [At-Tariq 86:5-7].
The scholars differed regarding the meaning of this verse. We have discussed their difference of opinion in the answer to question no. 118879 .
We think that what is most likely to be correct is the view of a group of commentators and scholars who said that the “backbone (as-sulb)” – which is the spine – and the “ribs (at-tara’ib)” – which are the bones of the chest – refer to the man himself.
-2-
Becoming male or female, and resembling either parent
There is a great deal of dispute among earlier and contemporary scholars regarding this matter. We will quote a number of hadiths which speak of the issue, then we will quote the most famous comments of the scholars regarding them.
i.
It was narrated from Anas that ‘Abdullah ibn Salam asked the Prophet (blessings and peace of Allah be upon him): Why does the child resemble its father or its mother? The Prophet (blessings and peace of Allah be upon him) said: “Jibril has informed me of that just now. As for the child, if the man’s water precedes the woman’s water, the child will resemble him, but if the woman’s water precedes the man’s water, the child will resemble her.” ‘Abdullah ibn Salam said: I bear witness that there is no god worthy of worship except Allah and that you are the Messenger of Allah. Narrated by al-Bukhari (3723).
What is meant by “resemble him” is that he will look like him.
ii.
It was narrated that Thawban, the freed slave of the Messenger of Allah (blessings and peace of Allah be upon him) said: I was standing beside the Messenger of Allah (blessings and peace of Allah be upon him) when one of the Jewish rabbis came and said: I have come to ask you about the child. He said: “The water of the man is white and the water of the woman is yellow.  If they meet and the water of the man prevails over the water of the woman, it will be a male, by Allah's leave. If the water of the woman prevails over the water of the man, it will be a female, by Allah’s leave.” The Jew said: You have spoken the truth. Narrated by Muslim (315).
iii.
It was narrated from Umm Sulaym that she asked the Prophet of Allah (blessings and peace of Allah be upon him) about a woman who sees in her dreams what a man sees (that, an erotic dream). The Messenger of Allah (blessings and peace of Allah be upon him) said: “If a woman sees that (that is, wetness), let her do ghusl.” Umm Salamah said: I felt shy because of that and I said: Does that really happen? The Prophet of Allah (blessings and peace of Allah be upon him) said: “How else does resemblance (of the child to either parent) happen? The water of the man is thick and white, and the water of the woman is thin and yellow. Whichever of them prevails, or comes first, the resemblance will be (to that parent).” Narrated by Muslim (311).
iv.
It was narrated from ‘A’ishah (may Allah be pleased with her) that a woman said to the Messenger of Allah: Should a woman do ghusl if she has an erotic dream and sees water? He said: “Yes… Can the resemblance (of the child to either parent) come except through that? If her water prevails over that of the man, then the child will resemble his maternal uncles, and if the man’s water prevails over hers, then he will resemble his paternal uncles.” Narrated by Muslim (314).
Here we will quote two scholarly views regarding the meaning of the hadiths quoted above, and the salient point here is the meaning of the words “precedes/comes before” and “prevails.”
-a-
Ibn al-Qayyim (may Allah have mercy on him) said:
If one of the two waters comes before the other, that will cause the child to resemble the parent whose water comes first. If one of the two waters prevails over the other, that will cause the child to be of the same gender as the parent whose water prevailed. So here we have two issues: preceding or coming before, and prevailing. Both may happen for one parent, or one will happen for one parent and the other will happen for the other parent. If the water of the man precedes the water of the woman and prevails over it, then the child will be male and will resemble the father. If the water of the woman precedes the water of the man and prevails over it, then the child will female and will resemble the mother. If one of them comes first and the other prevails, then the child will resemble the parent whose water came first, and will be male or female according to which parent’s water prevails."(Tuhfat al-Mawdud bi Ahkam al-Mawlud  p. 278).
-b-
Al-Hafiz Ibn Hajar (may Allah have mercy on him) said:
Muslim narrated from ‘A’ishah: “If the man’s water prevails over the woman’s water, the child will resemble his paternal uncles, and if the woman’s water prevails over the man’s water, the child will resemble his maternal uncles.” A similar report was narrated by al-Bazzar from Ibn Mas‘ud, in which it says: “The man’s water is white and thick and the woman’s water is yellow and thin. Whichever of them prevails, the child will resemble that parent.” What is meant by prevailing is coming first, because everything which comes first becomes dominant, so it prevails in a metaphoric sense.
As for what was narrated by Muslim in the marfu‘ hadith of Thawban, that “The water of the man is white and the water of the woman is yellow.  If they meet and the water of the man prevails over the maniy of the woman, it will be a male, by Allah's leave. If the water of the woman prevails over the maniy of the man, it will be a female, by Allah’s leave,” there is a problem with this report, which is that it implies that the child will inevitably resemble the paternal uncles if the father’s water prevails, and the same time the child will be male and not female, and vice versa. But what we see in real life is different, because the child may be male and resemble his maternal uncles, not his paternal uncles, and vice versa. Al-Qurtubi said: We must understand the hadith of Thawban on the basis that what is meant by prevailing is coming first. I say: What appears to be the case is what I noted above, which is that we may interpret prevailing as mentioned in the hadith of ‘A’ishah in a different way. As for the hadith of Thawban, prevailing may be understood in accordance with its apparent meaning, so preceding or coming first is what will determine whether the child is male or female, and prevailing is what will determine whether the child resembles the mother or the father. Thus the problem is resolved. It is as if what is meant by that prevailing which determines who the child resembles is being greater in size and volume, so that the water of the other one is overwhelmed and absorbed, and this determines who the child resembles. That may be divided into six categories:

When the man’s water comes first and is greater in quantity, so the child will be male and resemble the father.
The opposite of that.
When the man’s water comes first, but the woman’s water is greater in quantity, so the child will be male but will resemble the mother.
The opposite of that.
When the man’s water comes first, but the two waters are equal in volume, so the child will be male, but will not resemble either parent.
The opposite of that.

Fath al-Bari (7/273).
To sum up the above:

Ibn al-Qayyim (may Allah have mercy on him) said, explaining the meaning of “coming first/preceding” and “prevailing” that whichever of the two waters comes first, the child will resemble the parent whose water comes first, and the prevailing of one of them will determine whether the child is male or female.
Ibn Hajar (may Allah have mercy on him) was of the view that whichever water comes first determines whether the child will be male or female, and whichever prevails determines who the child resembles.

The matter is open to possibilities. Perhaps modern medical facts – not theories – will lend support to one of the two views. You can refer to specialist books on the topic for more information.
And Allah knows best.