The mitzvah of pidyon sh’vuyim, the redemption of captives, is considered one of our highest moral obligations. The Talmud (Bava Batra 8a-b) describes it as being even a greater mitzvah that tzedakah (charity), and Maimonides waxes eloquently in its praise: “there is no mitzvah as great as the redemption of captives” (Mishneh Torah, Hilkhot Matanot Aniyim 8:10). But, in response to your question, there are limits to what we are required to do in order to fulfill this obligation. The Mishnah (Gitin 4:6) instructs that we are not to redeem captives “at a sum greater than their monetary value.” (How this value is to be measured is an interesting question, but it isn’t our concern at the moment.) The reason it gives for this is mipnei tikun olam, a phrase that might be translated either as “for the protection/welfare of society” or “in order to prevent abuses.” What might these abuses be? The Talmud (Gitin 45a) offers two alternative theories: (1) payment of exorbitant ransoms might bankrupt the community; (2) the knowledge that the community will pay dearly to redeem their captives might tempt would-be kidnappers to seize more hostages. The commentators note that there is a significant practical difference between these two theories. If we follow the first rationale – we do not wish to bankrupt the community – then exorbitant ransoms might be permitted if they are paid from private sources (e.g., a wealthy family) rather than from the public treasure. If our major concern is rationale (2), however, then we might forbid the paying of exorbitant ransoms no matter what the source of the funds. Meanwhile, the very same mishnah cited above fixes another limitation to this mitzvah: we should not try to help captives escape from their keepers. This rule is again explained by the phrase mipnei tikun olam. The concern, as the Talmud notes (Gitin 45a), is that such attempts at rescue will cause the captors to treat their prisoners more harshly.
The question for us is: what do we learn from the “limits” that the tradition places upon the mitzvah of pidyon sh’vuyim? Let’s take your example, that of prisoner exchanges. Based upon a literal reading of the sources I’ve indicated above, we might conclude that Jewish tradition takes a negative view of the decision of the government of Israel to exchange many prisoners, some of whom are convicted terrorists and murderers, to secure the release of one captive Israeli soldier. After all, this is an “exorbitant” ransom, and the government’s willingness to pay it can only encourage the terrorists’ further kidnapping attempts. But before we draw that conclusion, let’s consider that the same texts would also prohibit the government from undertaking attempts to rescue prisoners. If we are forbidden both to meet the terrorists’ ransom demands and to undertake efforts at forcible rescue, what practical options remain? How can we ever hope to return our hostages from captivity?
We should keep in mind that the Talmudic and halakhic sources were written in a very different time than our own. The Rabbis were speaking in the context of a Jewish community that lived under the domination of great empires, a community that had to measure its actions carefully in order not to draw the ire of a hostile government. Today’s context is a very different one. Israel is a sovereign state; the government of Israel must act like a sovereign government, not like the leaders of a minority Jewish community that lives at the sufferance of the dominant host society and that must toe the line drawn by that society. To act as a sovereign state may require the making of tough decisions, one way or the other, that do not precisely comport with the limits established by the Talmud. All this is simply a long way of saying that, when the world changes, the law must take those changes into account. We cannot allow our texts to impose limitations upon our freedom of action that were befitting to a world that has long since passed.
What we can learn from our texts, however, is that moral decisions are never easy. It may be a mitzvah to redeem captives, but there are other values we must take into account before we rush blindly into action. The tradition, I think, teaches us to weigh these values carefully. It then permits us to make the best decision available in our time and our situation.