To complement the answer by @Uma:
General rule: A Muslim should not kill another Muslim intentionally
وَمَا كَانَ لِمُؤْمِنٍ أَن يَقْتُلَ مُؤْمِنًا إِلَّا خَطَأً
And never is it for a believer to kill a believer except by mistake.
— Surah An-Nisa [4:92-93]
The verse above is a general rule, but it has an exemption ("by mistake"). The verse is believed to have been revealed when 'Ayyāsh ibn Abi Rabī'ah (the half-brother of Abu Jahl) killed Al-Hārith ibn Yazīd on the day of the conquest of Mecca. Al-Hārith used to torture 'Ayyāsh because of Islam during his days in Mecca. 'Ayyāsh then came to realize that Al-Hārith had already embraced Islam, so he went to the Prophet ﷺ telling him what had happened. The verse was then revealed and is considered to be one of the "mothers of rulings" (see Tafsīr Al-Qurtubi 6/255)
The Prophet ﷺ later confirmed the same ruling during his last pilgrimage:
عَنْ جَرِيرٍ، أَنَّ النَّبِيَّ صلى الله عليه وسلم قَالَ لَهُ فِي حَجَّةِ الْوَدَاعِ ❬ اسْتَنْصِتِ النَّاسَ ❭ فَقَالَ ❬ لاَ تَرْجِعُوا بَعْدِي كُفَّارًا يَضْرِبُ بَعْضُكُمْ رِقَابَ بَعْضٍ ❭
Narrated Jarir: The Prophet (ﷺ) said to me during Hajjat-al-Wida': "Let the people keep quiet and listen." Then he said (addressing the people): "Do not revert to disbelief after me by striking the necks [cutting the throats] of one another [killing each other].
— Sahih al-Bukhari, Book 3, Hadith 63
The exemptions for intentional killing
In addition to unintentional killing or unknowingly killing a Muslim as mentioned in 4:92-93, there is no known disagreement among scholars that specific rulings by the Muslim ruler or one of his appointees may serve as additional exemptions:
وَلَا تَقْتُلُوا النَّفْسَ الَّتِي حَرَّمَ اللَّهُ إِلَّا بِالْحَقِّ وَمَن قُتِلَ مَظْلُومًا فَقَدْ جَعَلْنَا لِوَلِيِّهِ سُلْطَانًا فَلَا يُسْرِف فِّي الْقَتْلِ ۖ إِنَّهُ كَانَ مَنصُورًا
And do not kill the soul which Allah has forbidden, except by right. And whoever is killed unjustly — We have given his heir authority, but let him not exceed limits in [the matter of] taking life. Indeed, he has been supported [by the law].
— Surah Al-Isra [17:33]
One such exemption is the qissās as per the following verse:
وَكَتَبْنَا عَلَيْهِمْ فِيهَا أَنَّ النَّفْسَ بِالنَّفْسِ وَالْعَيْنَ بِالْعَيْنِ وَالْأَنفَ بِالْأَنفِ وَالْأُذُنَ بِالْأُذُنِ وَالسِّنَّ بِالسِّنِّ وَالْجُرُوحَ قِصَاصٌ
And We ordained for them therein a life for a life, an eye for an eye, a nose for a nose, an ear for an ear, a tooth for a tooth, and for wounds is legal retribution.
— Surah Al-Ma'idah [5:45]
Shafi'is view on a Muslim who does not pray
The Reliance of the Traveller is a book on the Shafi'i school of jurisprudence. Within this school, there is a disagreement about the killing of a person who does not pray. Both agree on the execution, but differ on its cause:
- Execution as a hadd for apostasy
- Execution as a hadd for deserting Islam and abandoning the community.
In his book Al-Umm 1/292, Imam Ash-Shafi'i concluded that whoever does not pray should be executed after three days of istitāba (request for repentance). The execution, in this case, is a hadd for deserting Islam and abandoning the community. This is based, not on the version of the hadith you quoted in Sunan an-Nasa'i 45/38 (sahih) through 'A'isha, but on the versions through 'Abdullah ibn Mas'ud, Abu Umamah ibn Sahl and 'Abdullah ibn 'Amir bin Rabi'ah. The version through 'Abdullah ibn Mas'ud is in Sahih al-Bukhari 87/17, Sunan Abi Dawud 40/2, and Sahih Muslim 28/34 (quoted below):
عَنْ عَبْدِ اللَّهِ، قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم: لاَ يَحِلُّ دَمُ امْرِئٍ مُسْلِمٍ يَشْهَدُ أَنْ لاَ إِلَهَ إِلاَّ اللَّهُ وَأَنِّي رَسُولُ اللَّهِ إِلاَّ بِإِحْدَى ثَلاَثٍ الثَّيِّبُ الزَّانِ وَالنَّفْسُ بِالنَّفْسِ وَالتَّارِكُ لِدِينِهِ الْمُفَارِقُ لِلْجَمَاعَةِ
'Abdullah (b. Mas'ud) reported Allah's Messenger (ﷺ) as saying: It is not permissible to take the life of a Muslim who bears testimony (to the fact that there is no god but Allah, and I am the Messenger of Allah, but in one of the three cases: the married adulterer, a life for life, and the deserter of his religion (Islam), abandoning the community.
— Sahih Muslim, Book 28, Hadith 34
Imam Ash-Shafi'i neither labeled the person as a Muslim nor as a non-Muslim.
Deserting Islam and abandoning the community
The phrase "deserter of Islam" (Arabic: التارك لدينه) has two interpretations:
- The deserter of Islam is one who apostates
- The deserter of Islam is one who abandons part of the religion, including but not limited to abandoning the community (or the main body of the Muslims).
With the interpretation that the person is an apostate, there is no known disagreement among the madhhabs nor within each madhhab that the hadd for apostasy is execution, and that an apostate does not get prayed upon the janāzah (funeral) prayer, does not get buried in a Muslim cemetery, and does not inherit nor be inherited. So this will not be discussed here. With the interpretation that a person remains a Muslim, the hadith shows that it is possible to have an execution hadd by abandoning part of the religion and abandoning the community. This view is expressed in Sahih Muslim bi Sharh al-Nawawi 1676, pp. 317-318 by An-Nawawi. He said that the phrase "deserting his religion, abandoning the community" covers:
- A general classification of anyone who apostates for any reason (executed if one does not revert to Islam after apostasy)
- A contextual classification specific to a certain group that remains as Muslims but abandons a part of the religion, let that be through innovation or transgression or otherwise, e.g., al-Khawarij.
The phrase "abandoning the community" (Arabic: المفارق للجماعه) or the main body of the Muslims, according to the majority of Shafi'i jurists, is defined as abandoning the Muslim community:
The discussion over what constitutes a community from linguistic, creed, and jurisprudence points of view is very long and has been debated by Al-Juwayni in his book Nihāyat al-Matlab, Ibn Daqiq al-'Id in his book Al-Ihkām, and other scholars.
This view that a Muslim may be executed due to a hadd is further strengthened through other hadiths that show that a Muslim may be executed as a hadd while being treated as a Muslim post-execution, i.e., gets prayed upon the janāzah prayer, gets buried in a Muslim cemetery, and is inherited by his family:
This list is not inclusive; just examples, and some are abrogated according to some scholars. We also know that Abu Bakr, during the Ridda wars, fought some tribes that claimed to be Muslims. Upon the death of the Prophet ﷺ, some groups rejected Islam in its entirety, some said they would stay as Muslims but claimed they have prophets among that would continue to add to the religion, and some said they would continue to be Muslims but would not practice all five pillars of Islam. Abu Bakr decided to fight them all, but 'Umar objected (initially) to fighting people who declare the shahadatayn. Abu Bakr's response was:
قال أبو بكر: والله لأقاتلن من فرق بين الصلاة والزكاة، فإن الزكاة حق المال. والله لو منعوني عقال كانوا يؤدونه إلى رسول الله صلى الله عليه وسلم، لقاتلتهم على منعه
Abu Bakr (May Allah be pleased with him) said: "By Allah, I would definitely fight him who makes the distinction between Salat and the Zakat because it is an obligation upon the rich to pay Zakat. By Allah, I will fight them even to secure the piece of rope which they used to give to the Messenger of Allah (ﷺ)."
— Riyad as-Salihin, Book 9, Hadith 220
'Umar realized afterward that Abu Bakr was correct. The conclusion is that it is permitted the execution of a Muslim who abandons part of the religion.
Praying is a criterion for forbidding execution
On another note, praying may serve as a stopper to any of the exemptions mentioned above (you may call it the exemption of exemptions for executing a Muslim). Some scholars interpret forbidding those who pray as saying that those who do not pray may be killed:
عَنْ أَبِي هُرَيْرَةَ، أَنَّ النَّبِيَّ صلى الله عليه وسلم أُتِيَ بِمُخَنَّثٍ قَدْ خَضَبَ يَدَيْهِ وَرِجْلَيْهِ بِالْحِنَّاءِ فَقَالَ النَّبِيُّ صلى الله عليه وسلم: مَا بَالُ هَذَا. فَقِيلَ يَا رَسُولَ اللَّهِ يَتَشَبَّهُ بِالنِّسَاءِ. فَأُمِرَ بِهِ فَنُفِيَ إِلَى النَّقِيعِ فَقَالُوا يَا رَسُولَ اللَّهِ أَلاَ نَقْتُلُهُ فَقَالَ: إِنِّي نُهِيتُ عَنْ قَتْلِ الْمُصَلِّينَ
Narrated AbuHurayrah: Am effeminate man (mukhannath) who had dyed his hands and feet with henna was brought to the Prophet (ﷺ). He asked: "What is the matter with this man?" He was told: "Messenger of Allah! He imitates the look of women." So he issued an order regarding him and he was banished to an-Naqi' (a region near Medina and not a Baqi'). The people said: Messenger of Allah! Should we not kill him? He said: "I have been prohibited from killing people who pray."
— Sunan Abi Dawud, Book 43, Hadith 156
According to some scholars, the 'illah (criterion) here is the prayers: long as one prays, one cannot be executed; but if one abandons praying, one may be executed.
From the long hadith below (in both Sahih al-Bukhari and Sahih Muslim), when a man insulted the Prophet ﷺ after distributing gold from Yemen among four men, Khalid ibn al-Waleed wanted to kill that person, but the Prophet ﷺ stopped him in case the man prayed:
فَقَامَ رَجُلٌ غَائِرُ الْعَيْنَيْنِ مُشْرِفُ الْوَجْنَتَيْنِ نَاشِزُ الْجَبْهَةِ كَثُّ اللِّحْيَةِ مَحْلُوقُ الرَّأْسِ مُشَمَّرُ الإِزَارِ فَقَالَ يَا رَسُولَ اللَّهِ اتَّقِ اللَّهَ. فَقَالَ: وَيْلَكَ أَوَلَسْتُ أَحَقَّ أَهْلِ الأَرْضِ أَنْ يَتَّقِيَ اللَّهَ. قَالَ ثُمَّ وَلَّى الرَّجُلُ فَقَالَ خَالِدُ بْنُ الْوَلِيدِ يَا رَسُولَ اللَّهِ أَلاَ أَضْرِبُ عُنُقَهُ فَقَالَ: لاَ لَعَلَّهُ أَنْ يَكُونَ يُصَلِّي. قَالَ خَالِدٌ وَكَمْ مِنْ مُصَلٍّ يَقُولُ بِلِسَانِهِ مَا لَيْسَ فِي قَلْبِهِ. فَقَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم: إِنِّي لَمْ أُومَرْ أَنْ أَنْقُبَ عَنْ قُلُوبِ النَّاسِ وَلاَ أَشُقَّ بُطُونَهُمْ
Then there stood up a person with deep sunken eyes, prominent cheekbones, and elevated forehead, thick beard, shaven head, tucked up loincloth, and he said: Messenger of Allah, fear Allah. He (the Holy Prophet) said: Woe to thee. Do I not deserve most to fear Allah amongst the people of the earth? That man then returned. Khalid b. Walid then said: Messenger of Allah, should I not strike his neck? Upon this he (the Holy Prophet) said: Perhaps he may be observing the prayer. Khalid said: How many observers of prayer are there who profess with their tongue what is not in their heart? Upon this, the Messenger of Allah (ﷺ) said: I have not been commanded to pierce through the hearts of people, nor to split their bellies (insides).
— Sahih Muslim, Book 12, Hadith 189