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:18:81

So we intended that their Lord should substitute for them one better than him in purity and nearer to mercy.  

So We desired that their Lord should give them in exchange (read yubaddilahumā or yubdilahumā) one better than him in purity, that is, in righteousness and God-fearing, and closer, than him, to mercy (read ruhman or ruhuman, in other words ˹it is to be understood as˺ rahmatan, ‘by way of mercy’) namely, ˹closer to˺ dutifulness towards his parents. Thus God, exalted be He, gave them in exchange a girl, who ˹afterwards˺ married a prophet and gave birth to a prophet through whom God guided an entire community.
القرآن:١٨:٨١

فَأَرَدْنَا أَنْ يُبْدِلَهُمَا رَبُّهُمَا خَيْرًا مِنْهُ زَكَاةً وَأَقْرَبَ رُحْمًا  

{فأردنا أن يبدِّلهما} بالتشديد والتخفيف {ربهما خيرا منه زكاة} أي صلاحا وتقى {وأقرب} منه {رحْما} بسكون الحاء وضمها رحمة وهي البرّ بوالديه فأبدلهما تعالى جارية تزوجت نبيا فولدت نبيا فهدى الله تعالى به أمة.