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

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,

Drash דְּרָשׁ

A mitzvah draws a mitzvah

One indulgence draws the next one after it. But one good deed also opens the way to others. The midrash shows this in the order of the laws.

Midrash Tanchuma reads the passages in a row. After the beautiful captive come two wives and strife at home, then the rebellious son. After the mitzvah of the bird's nest come a new house, a vineyard, oxen, clothing, a wife and children. A sin draws a sin, a mitzvah draws a mitzvah.

How Midrash Tanchuma explain it

Midrash Tanchuma When you go out to war

Our teachers taught: a mitzvah draws a mitzvah after it, and a sin draws a sin after it. "And you see among the captives," and so on, "and she shall shave her head and let her nails grow," so that she will not find favor in your eyes. What is written after this? "If a man has two wives," and so on. Two in the house, strife in the house. And more: one is loved and the other hated, or both are hated. What is written after this? "If a man has a stubborn and rebellious son." Whoever takes a beautiful captive will have from her a stubborn and rebellious son.

So it is written of David. Because he desired Maacah, daughter of Talmai, king of Geshur, when he went out to war, Avshalom (Absalom) came from him, who sought to kill him and lay with his ten concubines in the sight of all Israel and in the sight of the sun. Through him many tens of thousands of Israel were killed, and he made a split in Israel. And Shimi (Shimei), son of Gera, and Sheva (Sheba), son of Bichri, and Achitofel (Ahithophel) were killed. And Mefiboshet (Mephibosheth) he killed, and set Tziva (Ziba) over all the house of Shaul (Saul).

And it was taught in a baraita: Rabbi Yosi says: is it because the stubborn and rebellious son ate half a pound of meat and drank half a log of undiluted wine that the Torah said to take him to court and stone him? Rather, the Torah reached the end of his mind. In the end he will squander his father's property with the idlers he ate and drank with, will seek what he is used to and not find it, will go out to the crossroads, kill and rob people. And the Torah said: let him die innocent and not die guilty. For the death of the wicked is a benefit to them and a benefit to the world.

After the stubborn and rebellious son it is written: "And if a man has a sin worthy of death and he is put to death." If he escaped one, he did not escape the other. We have learned that a sin draws a sin after it.

And from where that a mitzvah draws a mitzvah? As it is written: "If a bird's nest happens before you, send away the mother," and so on, "that it may go well with you and you may prolong your days." What is written after this? "If you build a new house" — you will merit to build a new house and make a parapet. What is written after this? "Do not sow your vineyard with a mixture" — you will merit a vineyard and will sow a field. What is written after this? "Do not plow with an ox and a donkey together" — you will merit oxen and donkeys. What is written after this? "Do not wear a mixture (שַׁעַטְנֵז)" — you will merit fine garments of wool and fine garments of linen. What is written after this? "Make yourself tassels" — you will merit the mitzvah of tzitzit. What is written after this? "If a man takes a wife" — you will merit a wife and children. So we have learned that a mitzvah draws a mitzvah after it and a sin draws a sin after it. Therefore these passages were set next to each other.

Takeaway

"A mitzvah draws a mitzvah, a sin draws a sin" are the words of Ben Azzai in the Mishnah (Avot 4:2). The midrash proves them by the order of the passages in the chapter.
Maacah, daughter of Talmai, king of Geshur, was Avshalom's mother (Shmuel II / II Samuel 3:3). The midrash takes her to be a captive taken in war.
Avshalom's revolt against his father, his deed with David's concubines and the deaths in that war are told in the book of Shmuel (Shmuel II / II Samuel 15–18).
The baraita on the rebellious son is in the Talmud, where Rabbi Yosi HaGlili says it (Sanhedrin 72a). A log is a small liquid measure.
Shaatnez (שַׁעַטְנֵז) is cloth of wool and linen together, which may not be worn (Devarim / Deuteronomy 22:11). Tzitzit are tassels on the corners of a garment (Devarim / Deuteronomy 22:12).
The editions differ on the line about Mefiboshet: one puts the name Ish-Boshet beside it. In the book of Shmuel, David spared Mefiboshet (Shmuel II / II Samuel 21:7) and gave his property to Tziva (Shmuel II / II Samuel 16:4).