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:4:66

And if We had decreed upon them, "Kill yourselves" or "Leave your homes," they would not have done it, except for a few of them. But if they had done what they were instructed, it would have been better for them and a firmer position ˹for them in faith˺.  

And had We prescribed for them: (the particle an, ‘that’, is explicative) ‘Slay yourselves’ or ‘Leave your habitations’, as We did for the Children of Israel, they would not have done it, that is, what has been prescribed for them, save a few (read nominative qalīlun, as a substitution; or read accusative qalīlan, as an exceptive clause) of them; yet if they had done what they were admonished to do, of obedience to the Messenger (s), it would have been better for them, and stronger in establishing, ˹a stronger˺ confirmation of their faith.
القرآن:٤:٦٦

وَلَوْ أَنَّا كَتَبْنَا عَلَيْهِمْ أَنِ اقْتُلُوا أَنْفُسَكُمْ أَوِ اخْرُجُوا مِنْ دِيَارِكُمْ مَا فَعَلُوهُ إِلَّا قَلِيلٌ مِنْهُمْ ۖ وَلَوْ أَنَّهُمْ فَعَلُوا مَا يُوعَظُونَ بِهِ لَكَانَ خَيْرًا لَهُمْ وَأَشَدَّ تَثْبِيتًا  

{ولو أنا كتبنا عليهم أن} مفسرة {اقتلوا أنفسكم أو اخرجوا من دياركم} كما كتبنا على بني إسرائيل {ما فعلوه} أي المكتوب عليهم {إلا قليل} بالرفع على البدل والنصب على الاستثناء {منهم ولو أنهم فعلوا ما يوعَظون به} من طاعة الرسول ﷺ {لكان خيرا لهم وأشد تثبيتا} تحقيقا لإيمانهم.