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

And We made it a deterrent punishment for those who were present and those who succeeded ˹them˺ and a lesson for those who fear Allah.  

And We made it, this punishment, an exemplary punishment, a lesson to dissuade others from doing what they did; for all the former times and for the latter, that is, for the people of that time or those that came later; and an admonition to such as who fear, God: these are singled out for mention here because they, in contrast to others, are the ones who benefit thereby.
القرآن:٢:٦٦

فَجَعَلْنَاهَا نَكَالًا لِمَا بَيْنَ يَدَيْهَا وَمَا خَلْفَهَا وَمَوْعِظَةً لِلْمُتَّقِينَ  

{فجعلناها} أي تلك العقوبة {نكالاً} عبرة مانعة من ارتكاب مثل ما عملوا {لما بين يديها وما خلفها} أي للأمم التي في زمانها وبعدها {وموعظة للمتقين} الله وخصوا بالذكر لأنهم المنتفعون بخلاف غيرهم.