There definitely is no compulsion upon entering Islam. No doubt about that. It is clear from Surah al-Baqarah 2:256: “Let there be no compulsion in [acceptance of] religion. Truth stands out clear from falsehood.” But in an Islamic society, when it comes to apostasy, it’s not as clear.
However, in an Islamic nation run by Shariah Law you can leave Islam (but I am ABSOLUTELY NOT IN ANY WAY AT ALL encouraging it and I pray with all my heart that no one leave Islam because of this) without punishment as long as you don’t publicize it or convince others to do the same as this would be spreading mischief in the land. Not publicizing it and instead keeping it to yourself is something I call “personal apostasy” in that you keep your denial of Islam after you accepted it between you and God or whatever god or gods you believe in now.
But actually publicizing your denial of Islam after accepting it and convincing others to do the same is what I call “public apostasy” and that is what I’m pretty sure is punishable. The reason is because an Islamic society run by the Shariah is, by definition, a theocracy. And any threat the the religion is a threat to the society because theocracies don’t believe in separation of religion and state.