Praise be to Allah.
If a person does Hajj when he is a kaafir in the sense of major kufr, then after that he becomes a Muslim, that Hajj does not count as the obligatory Hajj, but if a person was a Muslim, then he apostatized by doing something that puts one beyond the pale of Islam, then he repented and returned to Islam, that Hajj does count as the obligatory Hajj for him, because he did Hajj when he was a Muslim. The Qur’aan indicates that the good deeds of an apostate before he apostatizes are only erased if he dies in kufr, because Allaah says (interpretation of the meaning):
“And whosoever of you turns back from his religion and dies as a disbeliever, then his deeds will be lost in this life and in the Hereafter, and they will be the dwellers of the Fire. They will abide therein forever”
And Allaah is the Source of strength. May Allaah send blessings and peace upon our Prophet Muhammad and his family and companions. End quote.
Standing Committee for Academic Research and Issuing Fatwas
Shaykh ‘Abd al-‘Azeez ibn ‘Abd-Allaah ibn Baaz, Shaykh ‘Abd al-Razzaaq ‘Afeefi, Shaykh ‘Abd-Allaah ibn Ghadyaan, Shaykh ‘Abd-Allaah ibn Qa’ood.