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:2:49

And ˹recall˺ when We saved your forefathers from the people of Pharaoh, who afflicted you with the worst torment, slaughtering your ˹newborn˺ sons and keeping your females alive. And in that was a great trial from your Lord.  

And, remember, when We delivered you, your forefathers: the address here and henceforth directed to those living at the time of the our Prophet, is about how God blessed their forefathers, and is intended to remind them of God’s grace so that they might believe; from the folk of Pharaoh who were visiting you with, that is, making you taste, evil chastisement, of the worst kind (the sentence here is a circumstantial qualifier referring to the person of the pronoun ˹suffixed˺ in najjaynākum, ‘We delivered you’); slaughtering your, newly-born, sons: this is explaining what has just been said; and sparing, retaining, your women, ˹doing so˺ because of the saying of some of their priests that a child born among the Israelites shall bring about the end of your rule ˹Pharaoh˺; and for you therein, chastisement or deliverance, was a tremendous trial, a test or a grace, from your Lord.
القرآن:٢:٤٩

وَإِذْ نَجَّيْنَاكُمْ مِنْ آلِ فِرْعَوْنَ يَسُومُونَكُمْ سُوءَ الْعَذَابِ يُذَبِّحُونَ أَبْنَاءَكُمْ وَيَسْتَحْيُونَ نِسَاءَكُمْ ۚ وَفِي ذَٰلِكُمْ بَلَاءٌ مِنْ رَبِّكُمْ عَظِيمٌ  

{و} اذكروا {إذ نجيناكم} أي آباءكم، والخطاب به وبما بعده للموجودين في زمن نبينا بما أنعم الله على آبائهم تذكيراً لهم بنعمة الله تعالى ليؤمنوا {من آل فرعون يسومونكم} يذيقونكم {سوء العذاب} أشده والجملة حال من ضمير نجيناكم {يُذبّحون} بيان لما قبله {أبناءكم} المولودين {ويستحيون} يستبقون {نساءكم} لقول بعض الكهنة له إن مولوداً يولد في بني إسرائيل يكون سبباً لذهاب ملكك {وفي ذلكم} العذاب أو الإنجاء {بلاء} ابتلاء أو إنعام {من ربكم عظيمْ}.

See similar narrations below:

Collected by Qurʾān
quran:7:141

And ˹recall, O Children of Israel˺, when We saved you from the people of Pharaoh, ˹who were˺ afflicting you with the worst torment - killing your sons and keeping your women alive. And in that was a great trial from your Lord.  

And, remember, when We delivered you (anjaynākum: a variant reading has anjākum, ‘He delivered you’) from Pharaoh’s folk who were inflicting upon you, ˹who were˺ burdening you and making you taste, terrible chastisement, the worst kind ˹of chastisement˺, namely, slaying your sons and sparing, retaining, your women; and therein, ˹in that˺ deliverance or chastisement, was a tremendous trial, ˹either˺ a grace or a tribulation, from your Lord, so will you not heed the admonition and desist from what you are saying?
القرآن:٧:١٤١

وَإِذْ أَنْجَيْنَاكُمْ مِنْ آلِ فِرْعَوْنَ يَسُومُونَكُمْ سُوءَ الْعَذَابِ ۖ يُقَتِّلُونَ أَبْنَاءَكُمْ وَيَسْتَحْيُونَ نِسَاءَكُمْ ۚ وَفِي ذَٰلِكُمْ بَلَاءٌ مِنْ رَبِّكُمْ عَظِيمٌ  

{و} اذكروا {إذ أنجيناكم} وفي قراءة أنجاكم {من آل فرعون يسومونكم} يكلفونكم ويذيقونكم {سوء العذاب} أشده وهو {يقتلون أبناءكم ويستحيون} يستَبْقون {نساءكم وفي ذلكم} الإنجاء أو العذاب {بلاء} إنعام أو ابتلاء {من ربِّكم عظيم} أفلا تتعظون فتنتهوا عما قلتم.
quran:14:6

And ˹recall, O Children of Israel˺, when Moses said to His people, "Remember the favor of Allah upon you when He saved you from the people of Pharaoh, who were afflicting you with the worst torment and were slaughtering your ˹newborn˺ sons and keeping your females alive. And in that was a great trial from your Lord.  

And, mention, when Moses said to his people, ‘Remember God’s grace to you when He delivered you from the folk of Pharaoh, who were inflicting upon you a dreadful chastisement, and were slaughtering your sons, the new-born, and sparing, keeping alive, your women — this was because some of the priests ˹of Egypt˺ had stated that a child born among the Israelites shall be the cause of the destruction of Pharaoh’s kingdom; and in that, deliverance — or ˹in that˺ chastisement — was a tremendous trial, grace — or ˹a tremendous˺ test — from your Lord.
القرآن:١٤:٦

وَإِذْ قَالَ مُوسَىٰ لِقَوْمِهِ اذْكُرُوا نِعْمَةَ اللَّهِ عَلَيْكُمْ إِذْ أَنْجَاكُمْ مِنْ آلِ فِرْعَوْنَ يَسُومُونَكُمْ سُوءَ الْعَذَابِ وَيُذَبِّحُونَ أَبْنَاءَكُمْ وَيَسْتَحْيُونَ نِسَاءَكُمْ ۚ وَفِي ذَٰلِكُمْ بَلَاءٌ مِنْ رَبِّكُمْ عَظِيمٌ  

{و} أذكر {إذ قال موسى لقومه اذكروا نعمة الله عليكم إذ أنجاكم من آل فرعون يسومونكم سوء العذاب ويذبِّحون أبناءكم} المولودين {ويستحيون} يستبقون {نساءكم} لقول بعض الكهنة إن مولودا يولد في بني إسرائيل يكون سبب ذهاب ملك فرعون {وفي ذلكم} الإنجاء أو العذاب {بلاء} إنعام أو ابتلاء {من ربكم عظيم}.