Muslim scholars agreed that disbelief makes deeds become worthless if the person died as a disbeliever. Allah says in the Holy Quran: “And whoever denies the faith his work has become worthless.” And He also says: “If they had associated others with Allah, then worthless for them would be whatever they were doing.” And He says: “Those who denied Our signs and the meeting of the Hereafter - their deeds have become worthless.”
If a person apostatized and then he repented so his previous deeds became worthless. Allah says in the Holy Quran: “If you should associate [anything] with Allah, your work would surely become worthless.” This statement is addressed to followers of the Prophet Mohamed (peace be upon him). It is obvious that this is a general statement; it is not only including people who apostatized and died as disbelievers. Therefore, Imam Malik, Imam Abu Hanifa, and Imam Ahmed according to one narration, said that if a Muslim apostatized and later he repented and came back to Islam then his deeds will not come back to him. If he had vows or expiation for oaths he will not be requested to fulfill any of that after his repentance. Also if he had done pilgrimage before his apostasy then he will be requested to go on pilgrimage again. And he will not be responsible for any of his action during his time of apostasy except for divorce and his action against others.
Nevertheless, Imam Shafi’i and Imam Ahmed, according to another narration, have another opinion. According to them, if an apostate repents then he will regain his good and bad deeds. This opinion is biased on the verse in which Allah said: “And whoever of you reverts from his religion [to disbelief] and dies while he is a disbeliever - for those, their deeds have become worthless in this world and the Hereafter, and those are the companions of the Fire, they will abide therein eternally.” Shafi’i understood from this verse that the worthlessness of deeds is only for apostates who died as disbelievers.