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:12:25

And they both raced to the door, and she tore his shirt from the back, and they found her husband at the door. She said, "What is the recompense of one who intended evil for your wife but that he be imprisoned or a painful punishment?"  

And they raced to the door: Joseph making for it in order to escape, while she, in order to grab hold of him, caught hold of his garment and pulled him towards her, and she tore his shirt from behind, whereupon they encountered her master, her husband, at the door. She, composed herself and then, said, ‘What is to be the requital of him who intends evil, ˹who intends˺ fornication, against your folk, but that he should be imprisoned, locked up in a jail, or ˹suffer˺ a painful chastisement?’, by having him beaten.
القرآن:١٢:٢٥

وَاسْتَبَقَا الْبَابَ وَقَدَّتْ قَمِيصَهُ مِنْ دُبُرٍ وَأَلْفَيَا سَيِّدَهَا لَدَى الْبَابِ ۚ قَالَتْ مَا جَزَاءُ مَنْ أَرَادَ بِأَهْلِكَ سُوءًا إِلَّا أَنْ يُسْجَنَ أَوْ عَذَابٌ أَلِيمٌ  

{واستبقا الباب} بادر إليه يوسف للفرار وهي للتشبث به فأمسكت ثوبه وجذبته إليها {وقدَّت} شقت {قميصه من دبر وألفيا} وجدا {سيدها} زوجها {لدى الباب} فنزعت نفسها ثم {قالت ما جزاء من أراد بأهلك سوءا} زنا {إلا أن يسجن} يحبس في سجن {أو عذاب أليم} مؤلم بأن يضرب.