The Prophet ﷺ said, "When the semen has remained in the womb for forty nights, the angel of souls comes to it and ascends with it to the Lord, holding it in his palm. He asks, 'My Lord, this servant of Yours, is it male or female?' Then Allah decrees concerning it whatever He decrees. The angel then asks, 'My Lord, is it to be wretched or blessed?' So what it is to encounter is written between its eyes."The narrator said, Abu Dharr then recited five verses from the opening of Surah at-Taghabun.
عن النبي ﷺ قال: ذا مكث المني في الرحم أربعين ليلة أتاه ملك النفوس فعرج به إلى الرب في راحته، فيقول: أي رب عبدك هذا ذكر أم أنثى، فيقضي الله إليه ما هو قاض، ثم يقول: أي رب أشقي أم سعيد؟ فيكتب بين عينيه ما هو لاق. قال: وتلا أبو ذر من فاتحة التغابن خمس آيات.
Uthman bin Saeed Darimi narrated it in Radd Ali Jahmiya (94), from Amr bin Khalid Harrani, who said, Ibn Lahia narrated to us, from Bakr bin Sawada, from Abu Tamim Jayshani, from Abu Dharr Ghifari, and he mentioned it.In the chain is Ibn Lahia, about whom there is well-known discussion. However, this hadith was also narrated from him by Abdullah bin Wahb, as Hafiz bin Qayyim mentioned in Shifa Alil (p. 20), and his narration from him is sound.