If a person is deemed to be a kaafir, all his deeds are invalidated. Allaah says (interpretation of the meaning):
“But if they had joined in worship others with Allaah, all that they used to do would have been of no benefit to them”
“And whosoever disbelieves in Faith, [i.e. in the Oneness of Allaah and in all the other Articles of Faith i.e. His (Allaah’s) Angels, His Holy Books, His Messengers, the Day of Resurrection and Al‑Qadar (Divine Preordainments)], then fruitless is his work; and in the Hereafter he will be among the losers”
A number of scholars are of the view that he is a not a kaafir in the sense of major kufr if he affirms that prayer is obligatory, but he is guilty of minor kufr, and this action of his is worse and more abhorrent than the action of the adulterer or thief and the like. Despite that, his fasting and Hajj are still valid, in their view, if he does them in the proper manner as prescribed in Islam. But his offence is that he is not praying regularly, and he is in grave danger of falling into major shirk according to a number of scholars. Some of them narrated that the majority are of the view that he is not a kaafir in the sense of major kufr if he does not pray because he is lazy or heedless, rather he is committing minor kufr thereby, but his crime is still serious and an abhorrent evil that is worse than adultery, stealing, disobeying one’s parents, drinking alcohol and so on. We ask Allaah to keep us safe and sound.
But the more correct of the two scholarly views is that he is a kaafir in the sense of major kufr – we ask Allaah to keep us safe and sound – because of the shar’i evidence quoted above. So if a person fasts but does not pray, his fasting does not count, and neither does his Hajj. End quote.