Shaykh al-Islam Ibn Taymiyyah(رحمه الله):
Most Muslims are born to two Muslim parents, essentially becoming Muslims by name, without there being any actual faith on their part. Then, when they reach puberty, from them are those that are blessed with actual faith, performing their obligations. Likewise, from them are those who perform these acts out of ingrained habit, and just to go along with his relatives, the people of the land in which he lives, etc.
For example, he gives Zakah simply because it is a habitual tradition that the ruler collects tax, and not because he realizes either the generality or specifics of the obligation to pay it. So, in his eyes, there is no difference between the innovated tax and the legislated Zakah. Such is the case with the inhabitant of Makkah who goes out to ‘Arafat every year simply because this is the way it is done, without realizing the generality or specifics of this being an act of worship of Allah.
So, the acts of worship performed by such people is invalid, without a doubt. In fact, the texts of the Qur’an and Sunnah, as well as the consensus of the Ummah, are clear in the ruling that these actions do not fulfill the obligation placed upon their doer…
So, the Islam of most people is by name, only. Rather, it (faith) only enters into their hearts during the course of the matter (i.e., later in their lives), if it enters at all. So, were this intention not to be obligatory upon them, they would not at all attempt to have it, and their hearts would be empty of it, and they would essentially be hypocrites, carrying out their actions out of habit and imitation, as is the case with many people.
[‘Majmu’ al-Fatawa’; 26/32]