Will the Muslim be rewarded for refraining from sin whatever the case?
Question

                There is someone who avoids some haraam things, not for fear of Allah, may He be glorified and exalted, but for fear of people, and he admits that he does that for the sake of people. For example, he avoids going to places where men and women mix freely, or to the disco, or to haraam parties, so that a certain person will not see him, and it is not for the sake of Allah, may He be glorified and exalted, and this person admits that. Is this regarded as minor shirk, or what? What about children who only pray so that their parents will be pleased with them, and they do not do it for Allah, may He be glorified and exalted?
Praise be to Allah.Firstly:
If someone refrains from committing a sin, then he must be refraining for one of the following reasons:

He refrains from sin out of fear of Allah. He will be rewarded for refraining from that sin, because the Prophet (blessings and peace of Allah be upon him) said in a hadith qudsi [that Allah said to the 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).
He refrains from sin so as to show off to people, and seeking their praise. He will not be rewarded for refraining from it; rather he may be sinning thereby, because refraining from sin is an act of worship, and acts of worship should only be done for 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.
End quote from Jaami‘ al-‘Uloom wa’l-Hikam (2/321).
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.
End quote from Shifaa’ al-‘Aleel, p. 170

He refrains from sin to avoid embarrassment before people. There is no sin on him in this case for refraining; however, he may be rewarded for refraining if that was done for a shar‘i purpose that Allah, may He be exalted, loves, such as if he refrained from sin lest his action lead to aspersions being cast upon the du‘aat [those who call people to Allah] and religious people.

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.
End quote from Shifa’ al-‘Aleel, p. 170

He refrains from sin because he has no interest in it, and his refraining is not out of fear of Allah or for the sake of 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.
End quote from Majmoo‘ al-Fataawa (10/738).
Secondly:
Acts of worship are not accepted from the Muslim unless two conditions are fulfilled:

The intention (niyyah) should be sincerely for the sake of Allah, may He be exalted, alone. 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.
It must be in accordance with the shar‘ that Allah, may He be exalted, has enjoined and has decreed that He is not to be worshipped except as He has prescribed. That is attained by following what the Prophet (blessings and peace of Allah be upon him) brought and not going against it, and not introducing any new acts of worship or new styles of performing acts of worship that are not proven to be soundly narrated from the Prophet (blessings and peace of Allah be upon him).

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:110].
Based on that, if a child prays for fear of his father or seeking to please his father, and does not intend alongside that to please Allah, then his prayer is not accepted, because prayer is an act of worship, and worship can only be done for Allah.
But if he intends in his prayer – which is usually the case – to please Allah, then to please his parents as a secondary objective, then in this case his prayer will be accepted, in sha Allah.
And Allah knows best.