If a person refrains from sinning then that must be done for one of the following reasons.
1. He is refraining from sinning because of fear of Allah. For refraining from that sin he will be rewarded. Prophet Muhammad(peace be upon him) said from the Hadith Qudsi that Allah said to angels: “and if he gives it (the bad deed) up for My sake, then record it for him as one good deed” Narrated by al-Bukhaari (7501).
2. A person is refraining from sinning so as to show off to the people and to seek their praise. In such a case a person will not be rewarded for that. Rather a person is sinning in this case because his intentions are not pure and refraining from sinning is an act of worship and the acts of worship should only be done for the sake of Allah.
Ibn Rajab said: But if he thinks of committing a sin then refrains from doing it out of fear of people, or to show off to them, then it was said that he will be punished for refraining from sin with this intention, because giving precedence to fear of people over fear of Allah is forbidden. Similarly, intending to show off to people is also forbidden. So if that (showing off) is combined with refraining from sin for that purpose, he will be punished for refraining.
Ibn al-Qayyim al-Jawziyyah (may Allah have mercy on him) said: … If someone refrains from (sin) for the sake of something other than Allah and not for the sake of Allah, he will be punished for refraining for the sake of something other than Allah, just as he would be punished for doing it for the sake of something other than Allah. This restraint and refraining is one of the deeds of the heart, and if it is done as an act of worship for something other than Allah, then he deserves punishment.
3. The person refrains from the sin to avoid embarrassment before the people. There is no sin in this case on the person however he will be rewarded only if he did this for the shari purpose.
Ibn al-Qayyim (may Allah have mercy on him) said – differentiating between this case and the previous one: If it is said: how can he be punished for refraining from sin to avoid embarrassment before people and to preserve his status among them, and for fear that they turn against him, when Allah, may He be glorified, does not condemn that or disallow it?
The answer is: undoubtedly he will not be punished for that. Rather he may be punished for seeking to draw closer to people by refraining from that sin and showing off to them thereby, so that they think that he refrained from it for fear of Allah and knowing that He is watching, when in reality that was not the case. So there is a difference between refraining from sin in order to draw closer to people and to show off to them, and refraining from sin to avoid embarrassment before them, and fear of their harm and that he may lose respect in their eyes. In this case he will not be punished for it; in fact he may be rewarded for it, if he did that for a purpose that Allah loves, such as upholding the status of the caller to Allah, and so that people will continue to listen to him and benefit thereby, and so on.
4. He is refraining from this sin because he is not interested in it and because he is not drawn towards it. He is not refraining it because of fear of Allah or any of his creation. In this case he will not be rewarded, and he is not sinning.
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said: This is the one who thinks of committing a bad deed, then he refrains from it either out of fear of Allah, or for some other reason. If he refrains from it out of fear of Allah, Allah will record an entire hasanah with Him for him, as is clearly stated in the hadith, and as it says in another hadith: “Record for him one hasanah, for He only refrained from it for My sake.”
Or he refrained from it for some other reason, in which case no bad deed will be recorded against him, as it says in another hadith: “If he does not do it, nothing will be recorded against him.” Thus the meanings of the different reports on this topic may be reconciled.
However, a Muslim must understand that an act of worship from him is not accepted unless two conditions are fulfilled.
1. the intention of the act of worship must only be for the sake of Allah. This means that in his words and deeds, both outward and inward, the individual is seeking Allah, may He be exalted, to the exclusion of all others.
2. It must be in accordance with the share that Allah, may He be exalted, has enjoined and has decreed that He is not to be worshipped except as He has prescribed. It includes following what Prophet Muhammad (Peace be upon him) has bought with him and what he has taught us. No one should introduce any new acts of worship or styles of performing any act of worship. There is no place for innovations in Islam.
The evidence for these two conditions is the verse in which Allah, may He be exalted, says (interpretation of the meaning):
“So whoever would hope for the meeting with his Lord - let him do righteous work and not associate in the worship of his Lord anyone” [al-Kahf 18:10].
And Allah knows best.