All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
First of all, we warn you against Waswaas (obsessive whispers), and we say that a Muslim does not go out of the fold of Islam except based on certainty.
Therefore, in principle, a Muslim remains a Muslim, and it is not ruled that he is an apostate from Islam just because of Waswaas or illusions or doubts.
Even if he has committed an act of Kufr (disbelief) unknowingly, then a general repentance is enough – Allah Willing – and it wipes out all his previous sins. Please, refer to fatwa 276013.
If a person commits an act of Kufr, he must repent by pronouncing the Shahaadah (the Two Testimonies of Faith) and regret what he has committed, and he is not a Muslim until he pronounces the Shahaadah.
However, all this applies only if it is certain that he committed an act that necessitate Kufr – we seek refuge in Allah from this.
Allah knows best.