I heard the Messenger of Allah ﷺ say, "When forty-two nights have passed over the drop of fluid, Allah sends an angel to it who shapes it and creates its hearing, sight, skin, flesh, and bones. Then the angel says, 'My Lord, is it male or female?' and your Lord decrees what He wills, and the angel writes it down. Then the angel says, 'My Lord, what is its lifespan?' and your Lord says what He wills, and the angel writes it down. Then the angel says, 'My Lord, what is its provision?' and your Lord decrees what He wills, and the angel writes it down. Then the angel goes out with the scroll in his hand, and nothing is added to what he was commanded nor anything diminished from it."In another narration, "The drop of fluid remains in the womb for forty nights, then the angel takes shape over it." Zuhayr said, "I think he said, 'the one who fashions it.'" The angel says, "My Lord, is it male or female?" and Allah makes it male or female. Then he says, "My Lord, sound or unsound?" and Allah makes it sound or unsound. Then he says, "My Lord, what is its provision, what is its lifespan, what is its nature?" Then Allah makes it wretched or happy.
سمعت رسول الله ﷺ يقول: إذا مر بالنطفة ثنتان وأربعون ليلة، بعث الله إليها ملكا فصورها، وخلق سمعها وبصرها وجلدها ولحمها وعظامها. ثم قال: يا رب أذكر أم أنثى؟ فيقضي ربك ما شاء. ويكتب الملك. ثم يقول: يا رب أجله؟ فيقول ربك ما شاء. ويكتب الملك. ثم يقول: يا رب رزقه؟ فيقضي ربك ما شاء. ويكتب الملك. ثم يخرج الملك بالصحيفة في يده فلا يزيد ما أمر ولا ينقص. وفي رواية: إن النطفة تقع في الرحم أربعين ليلة، ثم يتصور عليها الملك. قال زهير: حسبته قال: الذي يخلقها: فيقول: يا رب أذكر أو أنثى؟ فيجعله الله ذكرا أو أنثى. ثم يقول: يا رب أسوي أو غير سوي، فيجعله الله سويا أو غير سوي. ثم يقول: يا رب ما رزقه، ما أجله، ما خلقه، ثم يجعله الله شقيا أو سعيدا.
Muslim reported it in the Book of Predestination (2645) from the hadith of Amr bin Harith, from Abu Zubayr Makki, that Amir bin Wathila told him that he heard Abdullah bin Masud say, "The wretched is he who is wretched in his mother's womb, and the fortunate is he who is admonished by the example of others." He then went to a companion of the Messenger of Allah ﷺ named Huzaifa bin Usayd Ghifari and told him this saying of Ibn Masud, so he said, "How can a man become wretched without any deed?" The man said to him, "Are you surprised at that? I heard the Messenger of Allah ﷺ say..." and then he related the hadith.The second narration was also reported by Muslim through another route, from Abu Tufayl, who said, "I visited Abu Sarihah, Huzaifa bin Usayd Ghifari, and he said, I heard the Messenger of Allah ﷺ with these two ears of mine say..." and he related the hadith.The scholars said, the way to reconcile these narrations is that the angel maintains constant attention and observation of the state of the sperm-drop, and he says, "O Lord, this is now a clot, this is now a lump of flesh," at their respective times. So at every stage he announces what it has become by the command of Allah, exalted is He, who knows best. The angel's speech and activity occur at specific times. This was stated by Nawawi. For further detail, see Sharh Nawawi li-Sahih Muslim.