Reference: Majmoo’ Fataawa Shaykh Saalih al-Fowzaan – p722
Question: If someone made the intention to commit a sin, but did not do it, would it be recorded against him or not?
Response: It is mentioned in a hadeeth, that if a Muslim made the intention to do a sin and did not do it, then it will be recorded for him as a good deed. And that is if he changed his mind from doing it (the sin) – out of fear of Allaah (Ta’aala). If, however, he did not do it (the sin) because he was unable to do so – despite having the intention to do it if he was able, then it is feared that he is sinful because of his intention.
And if he made the intention to commit a sin and did not do it out of fear of Allaah (Subhaanahu wa Ta’aala) and a dislike for this sin – having changed his mind from doing it, then he will be rewarded for this, and it will be recorded as a good deed for him – just as it is [mentioned] in the hadeeth of the Prophet ﷺ.
 Transmitted by al-Bukhaaree, no.6491 and Muslim, no.131