Some people were safeguarded through an exhortation given by someone they wanted to be an accomplice in sin. An example of this lies with one of the three who entered the cave that was subsequently blocked by a boulder. The hadith mentions that one of them, when he lay with the woman ready to perform acts of intimacy, she said, ‘Fear Allah and do not break the seal except by due right,’ so he left her. (Bukhari)
A man sought to seduce a woman and ordered her to lock the doors, which she did. She then said, ‘One door remains open.’ He asked, ‘What door would that be?’ She replied, ‘The door between Allah, Mighty and Magnificent, and us.’ So he turned away from her.
Another sought to seduce a desert Arab. He said, ‘Who is there to see us save the stars?’ ‘What of the One who put them there?’ she replied. (ibn Jawzi Dhamm al-Hawa)
All of these are examples of Allah’s providence and His intervening between the servant and his committing sin. While mentioning the sinners, al-Hasan said, ‘Their worth was diminished with Him, so they disobeyed Him. Were they to have held a position of worth and honour with Him, He would have preserved them.’
Bishr said, ‘One who is noble or honoured would never persist in disobeying Allah and neither would the sagacious give preference to this world over the Hereafter.’
The Legacy of the Prophet Ibn Rajab Al-Hanbali p 46-48