if a person is known for certain to be a spy who informs the enemies of Islam against the Muslim fighters, he is to be executed. Spies are to be treated as apostates, if their acts of spying have resulted in enabling the enemies of Islam to tighten their grip on the Muslim countries and assassinate the Muslim fighters who defend their countries and rights.
It should be noted that executing spies is to be carried out by the people in authority in the Muslim countries. It is of a paramount importance to have clear-cut proofs in order to give a verdict of guilty in cases of spies. Verdicts in this respect are not to be based on mere accusations or doubts.
he who has yielded to temptations and betrayed his country is to review his attitude and give up this grave sin. He is to bear in mind that if he continues in this thorny route, whatever worldly benefit he gets will be temporary and that the shame will stain him until the Day of Judgment.
the Encyclopaedia of Definitions (Mafahim) produced by Al-Azhar Research Academy states: “Examples of treason include abandoning an order of Almighty Allah, committing something, which has been prohibited by Almighty Allah, disobeying an order of the Prophet (peace and blessings be upon him), and embezzling from something that has been entrusted to someone.
Allah, the Almighty says, “O you who believe! betray not the trust of Allah and the Messenger, nor misappropriate knowingly things entrusted to you.” (Al-Anfal: 27)
accordingly, whoever informs the Jews [or any enemy of Islam] about the Muslim fighters who defend their countries and rights, and thus helps them to target the Muslims, is to be executed. This is because whoever wilfully contributes to the assassination of someone in one way or another is also considered, in the point of view of Islamic law, an assassinator.
A Muslim who cooperates with the enemies of Islam against the interests of his fellow Muslims in this way is betraying Almighty Allah, His Messenger, the religion of Islam, and all the Muslims. Hence, Muslim scholars have given a fatwa to the effect that spies are to executed because of the great harm they cause to the Muslims. [In other words,] the hirabah penalty is to be applied to them.
however, it is to be kept in mind that accusing someone of being a spy is a serious matter that requires clear-cut and decisive evidence.
Sheikh HasanMa’mun, said: Spying for the interest of the enemies of Islam is an act that jeopardizes the interests of the Muslims. This is spreading corruption and mischief that entail the application of the hirabah penalty referred to in the Qur’an, ”The punishment of those who wage war against Allah and His Messenger, and strive with might and main for mischief through the land is: execution, or crucifixion, or the cutting off of hands and feet from opposite sides, or exile from the land: that is their disgrace in this world, and a heavy punishment is theirs in the Hereafter. (Al-Ma’dah: 33)
Muslim scholars are of two opinions regarding the ruling to be applied to those who wage war against Allah and His Messenger and those who spread corruption and mischief as stated in the above verse.
the first point of view is that a person who has committed such a crime is to be judged according to the amount and gravity of the harm he has caused to the Muslim community.
the second opinion is that the Imam is to choose one of the punishments referred to in the hirabah verse and that is to be applied to that person. The wisdom behind passing severe punishments according to this verse is to ensure the safety of the Muslims in their countries.
Whoever spies against the Muslims and provides their enemies with military secrets that may enable them to target the Muslims and cause them harm falls under the category of those who wage war against Allah and His Messenger.

In his book TafsirAl-Manar, the late Sheikh Rashid Reda said: Allah, the Almighty has made warding off evil and corruption and establishing right and justice among people a framework for passing rulings based on scholarly reasoning for cases where there is no clear-cut established ruling in the Shari`ah.
Allah, the Almighty has allowed the believers to fight against those who are corrupt in the story of Prophet David and Goliath. He, the Almighty says in this regard, “And when they went into the field against Goliath and his hosts, they said: Our Lord! Bestow on us endurance, make our foothold sure, and give us help against the disbelieving folk. So they routed them by Allah’s leave and David slew Goliath; and Allah gave him the kingdom and wisdom, and taught him of that which He wills. And if Allah had not repelled some men by others the earth would have been corrupted. But Allah is a Lord of Kindness to (His) creatures.” (Al-Baqarah: 250-251)
the saying of Allah, the Almighty here, ”And if Allah had not repelled some men by others the earth would have been corrupted…” indicates that He, the Almighty has established a principle for just people to repel corruption by any possible means.] This was also the reason why Allah, the Almighty gave the early Muslims permission to fight the polytheists for the first time. Allah, the Almighty says in this respect, “Sanction is given unto those who fight because they have been wronged; and Allah is indeed Able to give them victory; those who have been driven from their homes unjustly only because they said: Our Lord is Allah – For had it not been for Allah’s repelling some men by means of others, cloisters and churches and oratories and mosques, wherein the name of Allah is oft mentioned, would assuredly have been pulled down. Verily Allah helps one who helps Him. Lo! Allah is Strong, Almighty.” (Al-Hajj: 39-40)
From this we can derive that warding off any evil and corruption that may befall the Muslims is the responsibility of the Muslims in authority. In this regard, there is no doubt that espionage against the interests of the Muslims is one of the evils that should be repelled and confronted sternly by applying severe punishments to those who dare betray their countries and spy against the Muslims.

Moreover, Sheikh `AtiyyahSaqr, former head of Al-Azhar Fatwa Committee, adds:
“Imam Al-Qurtubi, an eminent scholar, said in his Tafsir: Whoever gives the enemies of Islam information about the secret affairs of the Muslims, without considering this activity to be lawful, is not to be judged as an apostate. Rather, it is up to the Imam in authority to decide what punishment should be applied to him. This is the opinion (of the eminent scholars) Imam Malik, Ibn Al-Qasim, and Ash-hab. (On the other hand,) Abdel-Malek, Imam Ahmad, and Ibn Al-Qayyim, who were also eminent scholars, were of the opinion that if a person was in the habit of giving the enemies of Islam information about the secret affairs of the Muslims, he is to be executed, for he is then a spy who falls under the category of those who wage war against Allah and His Messenger and cause corruption and mischief.

Finally, Dr. Ahmad Yusuf Abu Halabiyah, the former Dean of the Faculty of Usul Ad-Din (Theology), the Islamic University, Palestine, concludes: It is an unforgivable and serious crime to betray one’s people through cooperating with Almighty Allah’s enemies and helping them target the Muslims who fight in His Cause. If it is proven beyond any shadow of doubt that a certain person has committed such a crime, the hirabah penalty is to be applied to him as mentioned in the hirabah verse.
As for the family of that person, if they did not know about his treason, they should be treated as loyal Muslims; they are not to be blamed for his crime. The wife, in that case, should demand divorce, for it is not lawful for her to stay with a man who has betrayed Allah, His Messenger, and all the Muslims.
We beseech Almighty Allah to deliver the Muslim Ummah from the danger and harm of such disloyal people.