Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) said that the Prophet (peace and blessings be upon him) said: "Whoever bears witness to 'La ilaha illallah, Muhammadur Rasulullah' (There is no god but Allah; Muhammad (peace and blessings be upon him) is the Messenger of Allah), it is not permissible to kill him except for three reasons: 1. as retaliation (qisas), 2. by stoning (for adultery), 3. if he apostatises and separates from the Muslims."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجنايات / 15844