In a post earlier this year, I discussed whether Jews may serve as spies if it requires violating prohibitions (link). I have since found an essay by R. Shlomo Goren on the subject (Mishnas Ha-Medinah, pp. 140-151). He addresses two halakhic issues.
1) An Israeli spy will usually have to pretend that he is not Jewish. While a Jew is allowed to act as if he isn’t Jewish in order to save his life, he isn’t allowed to say that he isn’t Jewish (Shulchan Arukh, Yoreh De’ah 257:2).
R. Goren explains that there are three types of prohibitions do not override life-threatening conditions — idolatry, bloodshed and sexual immorality. If one may not pretend to be a non-Jew in order to save one’s life, it must be because it falls under the prohibition of idolatry. Therefore, he suggests, since Muslims are not idolators or polytheists, one is allowed to say that one is a Muslim in order to save lives. There is no issue of idolatry. He does not discuss spies who have to pretend that they are Christians or Hindus.
2) Spies often have to marry spouses from the enemy nation in order to avoid suspicion. This presumably falls under the category of sexual immorality and, therefore, does not override life-threatening considerations.
R. Goren makes two arguments to permit this. First, he deduces from Rishonim that even though marrying a gentile is forbidden, it is not technically classified as sexual immorality (arayos). It is a prohibition of its own. Therefore, it is permitted in life-threatening situations. Furthermore, we see from the case of Yael, who slept with Sisera in order to save the Jewish people (Nazir 23b), that even sexual immorality is permitted in order to save the Jewish people. Both of these reasons, R. Goren states, are sufficient to allow Israeli spies to intermarry.