He does so out of sincerity to Allah. This is required in all acts of worship both outward and inward. Allah the Almighty says:
And they were not commanded except to worship Allah, [being] sincere to Him in religion, inclining to truth. (Al-Bayyinah 98:5)
It means that they are sincere to Allah in their work. They were not only commanded to worship, but to worship sincerely. It was narrated on the authority of Abu Hurairah (may Allah be pleased with him) that the Prophet (peace be upon him) said that Allah says in a Hadith Qudsi (divine hadith): “The fasting person leaves his food and drink for Me; fasting is for Me and I shall reward it.” (Al-Bukhari)
The first part of the hadith develops in a person a desire to dedicate his deeds to Allah Almighty Alone and fosters the principle of avoiding ostentation and insincerity to Allah the Almighty in both outward and inward actions.
A reported narration reads: “There is no ostentation in fasting.”
Al-Hafizh Ibn Hajar (may Allah have mercy upon him) comments,
“It means that ostentation does not enter fasting by action; ostentation may enter it by words, such as when a person tells people that he is fasting. “Fasting is for Me.”
This is one of the meanings of fasting. It is a secret between the slave and his Lord, and there is no element of showing off involved.
The second meaning is that fasting is not subject to decrease, when it is requited on the Day of Resurrection, as it is narrated: “Every good deed is expiation, yet fasting is for Me, and I will reward for it.” (Al-Bukhari)
In another narration: “All the deeds of man are expiation for him except for fasting.” (Ahmad)
The best explanation of this meaning is what Sufyan ibn Uyaynah (may Allah have mercy upon him) said “This is one of the most valuable and precise Hadiths. On the Day of Resurrection, Allah the Almighty will take His slave to account and compensate for his wrongdoings from his deeds till nothing remains except fasting. Then, Allah will settle on the slave’s behalf the rest of his wrongdoings and admit the slave to Paradise because of fasting.” (Al-Bayhaqi)
Ibn Rajab (may Allah have mercy upon him) said, “Therefore, the Hadith means that fasting is for Allah, and there is no way for anyone to take the reward of fasting. The reward of fasting is stored by Allah the Almighty for its doer.” In general, fasting is training on sincerity to Allah The Almighty in all actions.
A Muslim who looks at the life of Salaf (our righteous predecessors, may Allah have mercy upon them) will find amazing situations due to their utmost sincerity. Let’s consider the following situations in their lives:
These people were sincere to Allah the Almighty, and thus Allah benefited so many people with their words. Therefore, a few words from the righteous predecessors are able to give life to many nations because they emerged from the hearts of sincere people.
It was said to Hamdun ibn Ahmad (may Allah have mercy upon him) “Why are the words of the righteous predecessors more useful than our words?” He said, “Because they spoke for the sake of the glory of Islam, the survival of the souls, and gaining the pleasure of Allah. However, we speak for the sake of the glory of the souls, the possession of this life, and gaining the pleasure of creation.”
However, this does not mean that a Muslim should leave work altogether in front of human beings for fear of showing off. Al-Fudayl ibn Iyad (may Allah have mercy upon him) said, “Quitting good deeds for the sake of people is showing off, whereas doing good deeds for the sake of people is associating partners with Allah. Sincerity is that Allah saves you from both of them.” Al-Hafizh An-Nawawi (may Allah have mercy upon him) said while commenting on the words of Al-Fudayl: “A Muslim who wants to do a righteous deed, then leaves it for fear of showing off in front of people shall be showing off by leaving this deed because he left this deed for the sake of people.”
Good deeds vary in that as some of them are performed collectively, such as Friday Prayers, and the daily congregational Prayers, leading Muslims in Prayer, announcing the Adhan (call to prayer), and the like. These deeds must be performed in public since they are the apparent symbols of Islam. There are other deeds that a Muslim carries out in secret. It is preferable to perform such deeds secretly, lest ostentation enters them – unless there is some benefit in doing them in public.
If you are doing a deed in secret and you feel sincerity towards Allah the Almighty in it, then, Satan whispers to you, “Someone is watching you, and you should quit that deed”, do not quit it. Go ahead and do not pay attention to the whisperings of Satan.