Devarim21:10

כִּי־תֵצֵא לַמִּלְחָמָה עַל־אֹיְבֶיךָ וּנְתָנוֹ יְהוָה אֱלֹהֶיךָ בְּיָדֶךָ וְשָׁבִיתָ שִׁבְיוֹ׃

When you go out to war against your enemies, and the Eternal your Almighty gives him into your hand, and you take captives from him,

Devarim 21:10

כִּי־תֵצֵא לַמִּלְחָמָה עַל־אֹיְבֶיךָ

Devarim / Deuteronomy 21:10 · Pshat

Devarim 21:10

כִּי־תֵצֵא לַמִּלְחָמָה עַל־אֹיְבֶיךָ וּנְתָנוֹ יְהוָה אֱלֹהֶיךָ בְּיָדֶךָ וְשָׁבִיתָ שִׁבְיוֹ׃

When you go out to war against your enemies, and the Eternal your Almighty gives him into your hand, and you take captives from him,

Pshat פְּשָׁט

What you go out for

You take on a hard task, and it opens leniencies that ordinary life does not have. It is easy to forget why you came at all.

Rashi: this is a war the people choose, not the war for their land. Or HaChaim: the Torah sets a condition. Go out to fight the enemies of the Eternal, not for the forbidden pleasures war permits. Then victory is promised.

How Rashi and Or HaChaim explain it

Rashi When you go out to war

The verse speaks of a war of choice (מִלְחֶמֶת הָרְשׁוּת). In the war for the Land of Israel one cannot say "and you take captives from him," since it has already been said: "Do not leave a soul alive" (Devarim / Deuteronomy 20:16).

Or HaChaim When you go out to war against your enemies, and so on

We must understand why all this needed to be said. It would have been enough to say: "And you see among the captives a beautiful woman," and so on. And further: once it says "when you go out to war," there was no need to add "against your enemies."

Perhaps the point is this. The verse comes to permit the beautiful captive, who is forbidden outside wartime, and also to permit pork shanks (Chullin 17a) and other forbidden things. And Scripture was concerned that when Israel go out to war, their feet would run to evil so as to enjoy what is forbidden. So the verse set a condition and said: "when you go out" — let your going out to war be to take vengeance on your enemies, who are enemies of the Eternal. As it says: "Do I not hate those who hate You, Eternal," and further: "they have become my enemies" (Tehillim / Psalms 139:21–22). For this let your going out be.

And if you do so, "the Eternal your Almighty gives him into your hand, and you take captives from him." From this you learn: if the going out is for another aim, and which aim is clear from what this passage is about, there is no promise that He will give the enemy into his hand.

Takeaway

A war of choice (מִלְחֶמֶת הָרְשׁוּת) is one the people wage by their own decision, unlike the war for the land commanded by the Torah. Sifrei opens this verse the same way (Sifrei Devarim 211).
Pork shanks are the Talmud's example: during the conquest of the land, soldiers were allowed to eat even these (Chullin 17a).
Or HaChaim reads "against your enemies" as the aim of going out, not a mere description: with another aim, the promise of victory does not hold.