All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
Ibn Al-Qayyim said: “There are three categories of abandoning (a sin): A category for which one is rewarded, a category for which one is punished, and a category for which one is neither rewarded nor punished.
The first is when a person abandons the sin because he knows that it is Islamically forbidden and he refrains from committing it for the Sake of Allaah, while he is able to commit it.
The second is like a person abandoning a sin for the sake of something other than Allaah; so he deserves punishment for abandoning it for the sake of other than Allaah in the same manner he deserves punishment for doing it for the sake of other than Allaah, as abandoning it and refraining from doing it are among the acts of the heart, and so, if one serves someone besides Allaah in one's heart, then he deserves punishment.
The third is like a person abandoning it (a sin) without thinking about it, or without knowing it, or loving it, or hating it, in the same manner a sleeping person or a child abandons it. If someone asks how a person can be punished for leaving a sin out of shame for people and for maintaining his respect in their sight and fearing that they might overcome him, while Allaah does not reprimand this or prevent it, then the answer is that there is no doubt that one is not punished for it, but one is punished for seeking people's favor by abandoning the sin and showing off to people by doing so in the same manner he abandoned it out of fear and heedfulness of Allaah, while in reality, in his heart, this is not the case. There is a difference between (a) abandoning a sin in order to get closer to them (the people) and showing off, and (b) abandoning it due to having shame for them and fearing their harm and fearing to be despised in their sight. In the latter case the person is not punished for it; rather he might be rewarded for it if it involves an objective that is pleasing to Allaah, like preserving the status of the Da’wah and winning their (the people's) trust, and so on.” [End of quote – excerpted from the book, Shifaa’ Al-‘Aleel]
Allaah Knows best.