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 · Sod

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,

Sod סוֹד

Learning from the opponent

Inside you is a voice that pulls toward the worse, and it works without tiring. You can resent it, or you can learn from it.

Ba'al Shem Tov reads the war as the struggle with the evil inclination (יֵצֶר הָרָע). It diligently carries out its errand from the Almighty: to tempt. A person takes a lesson from it: to be just as diligent in not listening to it. So the enemy is defeated by its own argument, and the captive becomes a teacher.

How Ba'al Shem Tov explain it

Ba'al Shem Tov 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

I heard from my teacher, may his memory be for life in the world to come, an explanation of the verse "When you go out to war against your enemies," and so on, "and you take captives from him." By the very argument of the evil inclination a person conquers the evil inclination. For it is diligent in its work, tempting a person to sin, in order to carry out the errand of the Almighty, blessed is He, as written in the Zohar in the parable of the harlot (Zohar, Terumah 163a). From this let a person take a lesson for himself: let him too be diligent in his work and not listen to the evil inclination, since that is the will of his Maker, blessed be His name, and so on. These are the words of a wise man, full of grace.

Takeaway

The passage is in "Sefer Baal Shem Tov," a collection of his teaching. The speaker is his student Rabbi Yaakov Yosef of Polonne, and "my teacher" is the Ba'al Shem Tov himself. The source is the book "Toldot Yaakov Yosef," portion Bechukotai.
The Zohar's parable: a king, wishing to test his son, hires a harlot to seduce him. She tries with all her might, yet secretly wants the son to stand firm (Zohar, Terumah 163a).
The evil inclination (יֵצֶר הָרָע) is the force in a person that pulls toward the worse. Here it is called a servant of the Almighty, not His opponent.
The "captive" becomes a lesson: from the opponent one takes what is good in it, its diligence.