The death penalty for apostasy is part of Islamic law. It’s based on the Qur’an:
“They wish you would disbelieve as they disbelieved so you would be alike. So do not take from among them allies until they emigrate for the cause of Allah. But if they turn away, then seize them and kill them wherever you find them and take not from among them any ally or helper.” (Qur’an 4:89)
A Sunni hadith depicts Muhammad saying:
“Whoever changed his Islamic religion, then kill him” (Bukhari 9.84.57). This is not just a Sunni idea; the death penalty for apostasy is part of Islamic law according to all the schools of Islamic jurisprudence.
This is still the position of all the schools of Islamic jurisprudence, both Sunni and Shi’ite. Sheikh Yusuf al-Qaradawi, the most renowned and prominent Muslim cleric in the world, has stated:
“The Muslim jurists are unanimous that apostates must be punished, yet they differ as to determining the kind of punishment to be inflicted upon them. The majority of them, including the four main schools of jurisprudence (Hanafi, Maliki, Shafi’i, and Hanbali) as well as the other four schools of jurisprudence (the four Shiite schools of Az-Zaidiyyah, Al-Ithna-‘ashriyyah, Al-Ja’fariyyah, and Az-Zaheriyyah) agree that apostates must be executed.”
Qaradawi also once famously said: “If they had gotten rid of the apostasy punishment, Islam wouldn’t exist today.”