Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:16:58

And when one of them is informed of ˹the birth of˺ a female, his face becomes dark, and he suppresses grief.  

And when one of them is given the tidings of a girl, that will be born to him, his face becomes darkened, transformed like that of one ˹suddenly˺ struck by grief, and he chokes inwardly, filled with anguish: so how is it that daughters are attributed to Him, exalted be He?
القرآن:١٦:٥٨

وَإِذَا بُشِّرَ أَحَدُهُمْ بِالْأُنْثَىٰ ظَلَّ وَجْهُهُ مُسْوَدًّا وَهُوَ كَظِيمٌ  

{وإذا بُشّر أحدهم بالأنثى} تولد له {ظل} صار {وجهه مسوداً} متغيراً تغير مغتَمّ {وهو كظيم} ممتلئ غمًّا فكيف تنسب البنات إليه تعالى.

See similar narrations below:

Collected by Qurʾān
quran:43:17

And when one of them is given good tidings of that which he attributes to the Most Merciful in comparison, his face becomes dark, and he suppresses grief.  

And when one of them is given the good tidings of that which he has attributed to the Compassionate One, ˹of that which˺ he has likened to Him by the ascription to Him of daughters — for a child is likened to its parent; in other words, when one of them is informed that a daughter has been born to him, his face becomes darkened, transformed into one laden with anguish, and he chokes inwardly, filled with anguish: so how can such a person then attribute daughters to Him? Exalted be He high above such ˹claims˺.
القرآن:٤٣:١٧

وَإِذَا بُشِّرَ أَحَدُهُمْ بِمَا ضَرَبَ لِلرَّحْمَٰنِ مَثَلًا ظَلَّ وَجْهُهُ مُسْوَدًّا وَهُوَ كَظِيمٌ  

{وإذا بشر أحدهم بما ضرب للرحمن مثلا} جعل له شبهاً بنسبة البنات إليه لأن الولد يشبه الوالد، المعنى إذا أخبر أحدهم بالبنت تولد له {ظل} صار {وجهه مسودا} متغيراً تغير مغتم {وهو كظيم} ممتلئ غما فكيف ينسب البنات إليه؟ تعالى عن ذلك.