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:24:8

But it will prevent punishment from her if she gives four testimonies ˹swearing˺ by Allah that indeed, he is of the liars.  

And the punishment, namely, the prescribed ˹legal˺ punishment for fornication that is established upon his testimony, shall be averted from her if she testify ˹swearing˺ by God four times that he is indeed lying, in accusing her of having fornicated;
القرآن:٢٤:٨

وَيَدْرَأُ عَنْهَا الْعَذَابَ أَنْ تَشْهَدَ أَرْبَعَ شَهَادَاتٍ بِاللَّهِ ۙ إِنَّهُ لَمِنَ الْكَاذِبِينَ  

{ويدرأ} أي يدفع {عنها العذاب} حد الزنا الذي ثبت بشهاداته {أن تشهد أربع شهادات بالله إنه لمن الكاذبين} فيما رماها من الزنا.