Cases of Applying Capital Punishment in Islam
Question

I'd like to know the reasons, justifications and conditions for the enforcement of capital punishment in Islam.
Praise be to Allah.Cases of applying capital punishment in Islam
Capital punishment in Islam applies in the case of a person who meets any of the following conditions: 

The apostate . The apostate is one who disbelieves after being a Muslim, because the Prophet (peace and blessings of Allah be upon him) said: “Whoever changes his religion, execute him.” Narrated by al-Bukhari, 6524. 
The married adulterer. The punishment in this case is stoning to death. 

Al-muhsan or the married person here means one who got married and had intercourse with his wife in the vagina, in a legitimate marriage in which both parties are free, of sound mind and adults. If a married man or woman commits adultery, then they are to be stoned to death, because the Prophet (peace and blessings of Allah be upon him) said: “Learn from me. Allah has given them a way out. If an unmarried person commits fornication with an unmarried person, (the punishment is) one hundred lashes and exile for one year. If a married person commits adultery with a married person, (the punishment is) one hundred lashes and stoning.” (Narrated by Muslim, 1690) 
And al-Bukhari (2725) and Muslim (1698) narrated from Abu Hurayrah and Zayd ibn Khalid al-Juhani (may Allah be pleased with them) that they said: “Two men from among the Bedouins came to the Messenger of Allah (peace and blessings of Allah be upon him) and said, ‘O Messenger of Allah, I adjure you by Allah to judge me according to the Book of Allah.’ The other disputant – who was smarter – said: ‘Yes, judge between us according to the Book of Allah and give me permission to speak first.’  
The Messenger of Allah (peace and blessings of Allah be upon him) said, ‘Speak.’ 
He said, ‘My son was employed by this man, and he committed adultery with his wife. I was told that the punishment for my son would be stoning, but that he could be ransomed for one hundred sheep and their offspring. I asked the people of knowledge and they told me that the punishment for my son would be one hundred lashes and exile for one year, and that this woman would be stoned.’  
The Messenger of Allah (peace and blessings of Allah be upon him) said: ‘By the One in Whose Hand is my soul, I will judge between you according to the Book of Allah. The offspring and sheep will be returned (i.e., there is no ransom), and your son is to be given one hundred lashes and exiled for one year. O Unays [who was one of the Companions], go tomorrow to that woman and if she admits (this crime) then stone her.’ So he went to her the next day and she admitted it, and the Messenger of Allah (peace and blessings of Allah be upon him) issued orders that she be stoned. 

The murderer (one who kills deliberately). He is to be killed in retaliation (qisas) unless the victim’s next of kin let him off or agree to accept the diyah (blood money), because Allah says (interpretation of the meaning): 

“O you who believe! Al-Qisas (the Law of Equality in punishment) is prescribed for you in case of murder: the free for the free, the slave for the slave, and the female for the female. But if the killer is forgiven by the brother (or the relatives) of the killed against blood money, then adhering to it with fairness and payment of the blood money to heir should be made in fairness. This is an alleviation and a mercy from your Lord. So after this whoever transgresses the limits (i.e. kills the killer after taking the blood money), he shall have a painful torment.” [al-Baqarah 2:178]
“And there is (a saving of) life for you in Al-Qisas (the Law of Equality in punishment), O men of understanding, that you may become Al-Muttaqun (the pious).” [al-Baqarah 2:179] 
And the Prophet (peace and blessings of Allah be upon him) said: “It is not permissible (to shed) the blood of a Muslim who bears witness that there is no god but Allah and that I am the Messenger of Allah, except in three cases: a married adulterer, a soul for a soul, or one who leaves the religion and splits from the jama’ah.”  (Narrated by al-Bukhari, 6484; Muslim, 1676) 

Bandits, i.e., al-muharib, the one who wages war against Allah and His Messenger. Allah says (interpretation of the meaning): 

“The recompense of those who wage war against Allah and His Messenger and do mischief in the land is only that they shall be killed or crucified or their hands and their feet be cut off from opposite sides, or be exiled from the land. That is their disgrace in this world, and a great torment is theirs in the Hereafter.” [al-Maidah 5:33]

Spies . The spy is the one who spies on the Muslims and transmits information to their enemies. 

The evidence for that is the report narrated by al-Bukhari (3007) and Muslim (2494) which says that Hatib ibn Abi Balta’ah wrote to some of the mushrikin in Makkah telling them some information about the Messenger of Allah (peace and blessings of Allah be upon him). The Messenger of Allah (peace and blessings of Allah be upon him) said: “O Hatib, what is this?” He said, “O Messenger of Allah, do not hasten to judge me. I was a man closely connected to Quraysh, but I did not belong to this tribe, while the other Muaajirin with you had their relatives in Makkah who would protect their families and property. So I wanted to make up for my lack of blood ties to them by doing them a favor so that they might protect my family. I did not do this because of disbelief or apostasy nor out of preferring kufr (disbelief) to Islam.” The Messenger of Allah (peace and blessings of Allah be upon him) said, “He has told you the truth.” ‘Umar said, “O Messenger of Allah! Let me chop off the head of this hypocrite!” The Messenger of Allah (peace and blessings of Allah be upon him) said: “He was present at the battle of Badr, and you do not know, perhaps Allah looked at the people of Badr and said, ‘Do whatever you like, for I have forgiven you.’” 
The point in this hadith is that the Prophet (peace and blessings of Allah be upon him) agreed with ‘Umar that Hatib deserved to be executed for this action, but the Prophet (peace and blessings of Allah be upon him) told him that there was a reason why he should not be killed, which is that he was one of those who was present at the battle of Badr. 
Ibn al-Qayyim said in Zad al-Ma’ad (2/115) concerning the hadith of Hatib ibn Abi Balta’ah: 
This was quoted as evidence by those who do not think that the Muslim spy should be killed, such as al-Shafi’i, Ahmad and Abu Hanifah (may Allah have mercy on them). And it was quoted as evidence by those who think that the spy should be killed, such as Malik and Ibn ‘Aqil among the companions of Ahmad, and others. They said: This is because the reason for not killing him was that he had been present at Badr. If being Muslim was the reason for not killing him, he would not have given a reason that is more specific, which is the fact that he had been present at Badr. 
And he said elsewhere in Zad al-Ma’ad (3/422): 
“The correct view is that execution of a spy depends on the opinion of the ruler; if executing him is in the Muslims’ interests, he should be executed, but if letting him live serves a greater interest, then he should be allowed to live. And Allah knows best. 
The above also includes the one who does not pray, the one who practices witchcraft , and the heretic, because they come under the heading of “the one who leaves his religion and splits from the jama’ah.” 
With regard to the conditions of implementing this punishment, there are many. Each crime has its own specific conditions, details of which may be found in the books of fiqh.  
And Allah knows best.