Under a Islamic country that is in accordance with the Sharia, public apostasy comes under two types: ordinary apostates and extreme apostates. Ordinary apostates are those who publicly come out as apostates but don’t want to wage war against Islam. Such people would not be put to death immediately; rather, they would be asked to repent three times, they would be given a chance to come back to Islam, and they would be asked about any doubts that they have that needs to be resolved. If they comes back to Islam, the death penalty is waived. But if they persists in their apostasy after that, they are to be put to death. Extreme apostates are those who publicly come out as apostates and want to wage war against Islam, whether it is verbal or physical. Such people would be put to death right away, whether or not they repented.
Now how is this justifiable in Islam? What people don’t realize is that public apostasy can be seen as a form of treason. In fact, public apostasy against a religiously run country is exactly the same as treason against a secularly run country. According to many countries around the world, including the United States of America, treason is punishable by death. Similarly, under Sharia, and even according to the Bible as well (Deuteronomy 13:6-11), apostasy is also punishable by death. But this doesn’t mean Islam is not tolerant to other religions; people who follow other religions that live in a Muslim land have their full right to practice their religion and be protected under the Muslims. This is because Muslims can’t force anyone to become a Muslim, rather, Allah says in the Quran, “Let there be no compulsion in religion, for the truth stands out clearly from falsehood. So whoever renounces false gods and believes in Allah has certainly grasped the firmest, unfailing hand-hold. And Allah is All-Hearing, All-Knowing” (Quran 2:256). One might ask, “if this is the case, how come apostates are still punished?” The difference is that when someone is publicizing their apostasy and letting people know they left Islam, as mentioned early, this can be seen as a form of treason against the country and can very quickly cause tribulations and trials for the people. As for one who is an apostate in his heart, he wouldn’t be punished by the Sharia for it.
And Allah knows best.