Indeed, a Muslim spy may have a special concession in carrying out certain things that are prohibited in normal situations. This very ruling is restricted to the norm of necessity, keeping in mind that we will all answer for our deeds on the Day of Judgment.
Sheikh Yusuf Al-Qaradawi, issues the following Fatwa: “Muslim jurists, who are committed to their religion, cannot give blessing to the illicit acts, such as drinking wine, Zina (adultery or fornication) committed by a Muslim who acts as a spy in favour of his country.
On the other hand, the spy who is true to his cause may be allowed to look as if he is drinking wine but not drinking it. He may also be permitted to perform the prayers beyond their appointed times, but he is not allowed to leave the prayer at all under the pretext that his job dictates doing so.
However, we can not allow one who works in such a field to commit illicit practices under the pretext that the role he shoulders and the information he gathers about the enemy will result in protecting his Muslim country against any future hazards that might be posed by the foes. Such a principle, giving an airing to the notion end justifies the means, which the West follows to the letter, is not accepted by us Muslims.
Our aim should be honest and our means should be pure. Referring to this, the Prophet (peace and blessings be upon him) is reported to have said: “Indeed Allah do not remove that, which is bad with something similar to it. Rather, He (Almighty) replaces that which is bad with something good. And He (Almighty) is Good, and accepts only that which is good.”
If the spy legalizes for himself committing Zina, drinking wine, abandoning prayers and fasting, then how could we guarantee his good intentions?! Most probably, this man, after given full rein to commit those forbidden practices, will back the enemy against us. It stands to reason that if one does such illicit practices, his efforts will end in total failure and hence we can not expect him to do any favor to back his fellow Muslims brothers, let alone Islam.
Finally, the one who is chosen to carry out such a noble role (i.e. spying for the sake of his Muslim country) should be of noble character, solid and unshakable creed that stands firm in facing any test of time or challenge to his faith and creed. The point here is, if that noble person has no means but to commit anything that violates the tenets of his faith, and his decline from such an illicit act will bring about harm to Muslims and will give the enemy the clues through which they can easily identify him, then he is allowed to commit that which is unlawful, keeping in mind that such a ruling (the permissibility of committing unlawful practices) is confined to the norm of necessity. Also, this ruling is so specific to the case in point only.”