"There is no greater mitzvah than redeeming captives," wrote the 12th century scholar Maimonides, one of the most influential rabbis of all times. But there is a caveat.
While Jewish religious law recommends large concessions to free captives, it also respects an ancient rabbinic regulation that one should not pay more than the "value" of the captured individual.
In the ancient world, calculating somebody's "value" was far easier than it is today. Ransoming people was commonplace and people had a sense of how much money was needed. Today, by contrast, Israel is unique in its predicament.
As far as some rabbis are concerned, it is common sense that an exchange rate of more than 1,000-1 is over the odds, and therefore prohibited by religious law. Former army Chief Rabbi Avichai Ronsky has come out against the deal, telling the Israeli media that it constitutes "complete surrender".
But other rabbis say that the idea of a "going rate" for captives applied only in the past, when civilians were ransomed for money.
"The halachah that one should not pay more than captives are worth does not apply to soldiers on missions," said Daniel Hershkowitz, rabbi of the Ahuza neighbourhood in Haifa and Israel's science and technology minister, after the cabinet voted on the exchange. This view won out in the cabinet room - all religious ministers backed the deal.
Shlomo Goren, the first Chief Rabbi of the Israeli army and leader of religious Zionism, came up with this interpretation. Recently, Ovadia Yosef, Israel's best-respected Sephardic rabbi and Yisrael Meir Lau, who is revered by Charedim and religious-Zionists alike, have endorsed his logic. The mainstream has followed this precedent and deemed the deal kosher.