Ramban explains the command to offer peace to distant cities while distinguishing the seven nations, whose destruction is bound up with their moral and religious corruption. He is a major source for understanding the command as a response to idolatry and societal evil, not ethnic animus.
כִּי תִקְרַב אֶל עִיר לְהִלָּחֵם עָלֶיהָ וְגוֹ', בְּמִלְחֶמֶת הָרְשׁוּת הַכָּתוּב מְדַבֵּר, כְּמוֹ שֶׁמְּפֹרָשׁ בָּעִנְיָן (דברים כ':ט"ו), כֵּן תַּעֲשֶׂה לְכָל הֶעָרִים הָרְחֹקֹת מִמְּךָ מְאֹד, לְשׁוֹן רַשִׁ"י (רש"י על דברים כ':י'). כָּתַב הָרַב זֶה מִסִּפְרֵי (שופטים קצט), שֶׁשָּׁנוּ שָׁם כַּלָּשׁוֹן הַזֶּה, בְּמִלְחֶמֶת הָרְשׁוּת הַכָּתוּב מְדַבֵּר. וְהַכַּוָּנָה לְרַבּוֹתֵינוּ בַּכָּתוּב הַזֶּה אֵינָהּ אֶלָּא לוֹמַר שֶׁהַפָּרָשָׁה בְּסוֹפָהּ תְּחַלֵּק בֵּין שְׁתֵּי הַמִּלְחָמוֹת, אֲבָל קְרִיאַת הַשָּׁלוֹם אֲפִלּוּ בְּמִלְחֶמֶת מִצְוָה הִיא שֶׁחַיָּבִים לִקְרֹא לְשָׁלוֹם, אֲפִלּוּ לְשִׁבְעָה עֲמָמִים, שֶׁהֲרֵי מֹשֶׁה קָרָא לְשָׁלוֹם לְסִיחוֹן מֶלֶךְ הָאֱמֹרִי וְלֹא הָיָה עוֹבֵר עַל עֲשֵׂה וְעַל לֹא תַעֲשֶׂה שֶׁבַּפָּרָשָׁה, כִּי הַחֲרֵם תַּחֲרִימֵם (דברים כ':י"ז), וְלֹא תְחַיֶּה כָּל נְשָׁמָה (דברים כ':ט"ז). אֲבָל הֶפְרֵשׁ שֶׁבֵּינֵיהֶם כַּאֲשֶׁר לֹא תַּשְׁלִים וְעָשְׂתָה מִלְחָמָה, שֶׁצִּוָּה הַכָּתוּב בָּרְחוֹקוֹת לְהַכּוֹת אֶת כָּל זְכוּרָהּ וּלְהַחֲיוֹת לָהֶם הַנָּשִׁים וְהַטָּף בַּזְּכָרִים, וּבְעָרֵי הָעַמִּים הָאֵלֶּה צִוָּה לְהַחֲרִים גַּם הַנָּשִׁים וְהַטָּף. וְכָךְ אָמְרוּ רַבּוֹתֵינוּ בְּמִדְרַשׁ אֵלֶּה הַדְּבָרִים רַבָּה (ה יג), וְהוּא עוֹד בְּתַנְחוּמָא וּבַגְּמָרָא יְרוּשַׁלְמִי (שביעית פ"ו ה"א), אָמַר רַבִּי שְׁמוּאֵל בְּרַבִּי נַחְמָנִי, יְהוֹשֻׁעַ בִּן נוּן קִיֵּם הַפָּרָשָׁה הַזּוֹ. מֶה עָשָׂה יְהוֹשֻׁעַ, הָיָה שׁוֹלֵחַ פְּרוֹסְדִיטְגְּמָא בְּכָל מָקוֹם שֶׁהָיָה הוֹלֵךְ לִכְבֹּשׁ, וְהָיָה כּוֹתֵב בָּהּ, מִי שֶׁמְּבַקֵּשׁ לְהַשְׁלִים יָבוֹא וְיַשְׁלִים, וּמִי שֶׁמְּבַקֵּשׁ לֵילֵךְ לוֹ יֵלֵךְ לוֹ, וּמִי שֶׁמְּבַקֵּשׁ לַעֲשׂוֹת מִלְחָמָה יַעֲשֶׂה מִלְחָמָה. הַגִּרְגָּשִׁי פָּנָה, הַגִּבְעוֹנִים שֶׁהִשְׁלִימוּ עָשָׂה לָהֶם יְהוֹשֻׁעַ שָׁלוֹם, שְׁלֹשִׁים וְאֶחָד מְלָכִים שֶׁבָּאוּ לְהִלָּחֵם הִפִּילָם הקב"ה וְכוּ'. וְכָךְ אָמַר הַכָּתוּב בְּכֻלָּם (יהושע יא יט כ), לֹא הָיְתָה עִיר אֲשֶׁר הִשְׁלִימָה אֶל בְּנֵי יִשְׂרָאֵל בִּלְתִּי הַחִוִּי יֹשְׁבֵי גִבְעוֹן אֶת הַכֹּל לָקְחוּ בַמִּלְחָמָה כִּי מֵאֵת ה' הָיְתָה לְחַזֵּק אֶת לִבָּם לִקְרַאת הַמִּלְחָמָה אֶת יִשְׂרָאֵל לְמַעַן הַחֲרִימָם, מִכְּלָל שֶׁאִם רָצוּ לְהַשְׁלִים הָיוּ מַשְׁלִימִים עִמָּם. וְנִרְאֶה שֶׁיֵּשׁ הֶפְרֵשׁ עוֹד בִּשְׁאֵלַת הַשָּׁלוֹם, שֶׁבֶּעָרִים הָרְחוֹקוֹת נִשְׁאַל לָהֶם לְשָׁלוֹם וְשֶׁיִּהְיוּ לָנוּ לָמַס וְיַעַבְדוּנוּ, אֲבָל בְּעָרֵי (הערים) הָעַמִּים הָאֵלֶּה נִשְׁאַל לָהֶם לְשָׁלוֹם וּמִסִּים וְעַבְדוּת עַל מְנָת שֶׁיְּקַבְּלוּ עֲלֵיהֶם שֶׁלֹּא לַעֲבֹד ע"ז. וְלֹא הִזְכִּיר הַכָּתוּב זֶה בַּפָּרָשָׁה הַזֹּאת, שֶׁכְּבָר נֶאֱסַר לָנוּ בְּעוֹבְדֵי ע"ז (שמות כג לג), לֹא יֵשְׁבוּ בְּאַרְצְךָ פֶּן יַחֲטִיאוּ אֹתְךָ לִי כִּי תַעֲבֹד אֶת אֱלֹהֵיהֶם. וְיִתָּכֵן שֶׁלֹּא נִצְטָרֵךְ לְהוֹדִיעַ לָהֶם רַק הַשָּׁלוֹם וְהַמִּסִּים וְהַשִּׁעְבּוּד, וְאַחֲרֵי שֶׁיִּהְיוּ מְשֻׁעְבָּדִים לָנוּ נַגִּיד לָהֶם שֶׁאָנוּ עוֹשִׂים מִשְׁפָּטִים בע"ז וּבְעוֹבְדֶיהָ, בֵּין יָחִיד בֵּין רַבִּים. וְכֵן מָה שֶׁנֶּאֱמַר כָּאן (דברים כ':י"ח), לְמַעַן אֲשֶׁר לֹא יְלַמְּדוּ אֶתְכֶם לַעֲשׂוֹת כְּכֹל תּוֹעֲבֹתָם, וְאָמְרוּ בְּסִפְרֵי (שופטים רב) הָא אִם עָשׂוּ תְשׁוּבָה אֵינָן נֶהֱרָגִים, בְּשִׁבְעַת עֲמָמִים הוּא, וְהַתְּשׁוּבָה הוּא שֶׁיְּקַבְּלוּ עֲלֵיהֶם שֶׁבַע מִצְוֹת שֶׁנִּצְטַוּוּ בְּנֵי נֹחַ, לֹא שֶׁיִּתְגַּיְּרוּ לִהְיוֹתָם גֵּרֵי צֶדֶק. וּבְמַסֶּכֶת סוֹטָה אָמְרוּ (לה) שֶׁכָּתְבוּ הַתּוֹרָה עַל הָאֲבָנִים בְּשִׁבְעִים לָשׁוֹן, וְכָתְבוּ לְמַטָּה לְמַעַן אֲשֶׁר לֹא יְלַמְּדוּ אֶתְכֶם לַעֲשׂוֹת, הָא אִם עָשׂוּ תְשׁוּבָה מְקַבְּלִים אוֹתָם. וְרַשִׁ"י פֵּרֵשׁ שָׁם לְהוֹדִיעַ לָאֻמּוֹת הַיּוֹשְׁבִים חוּץ מִגְּבוּלָם שֶׁל אֶרֶץ יִשְׂרָאֵל שֶׁלֹּא נִצְטַוּוּ לְהַחֲרִימָם אֶלָּא עַל אוֹתָן שֶׁבְּתוֹךְ הַגְּבוּלִים כְּדֵי שֶׁלֹּא יְלַמְּדוּ אוֹתָם מַעֲשֵׂה קִלְקוּלָם, אֲבָל אוֹתָם הַיּוֹשְׁבִים חוּצָה לָהּ אוֹמְרִים לָהֶם, אִם אַתֶּם חוֹזְרִים בִּתְשׁוּבָה נְקַבֵּל אֶתְכֶם, וְשֶׁבְּתוֹכָהּ אֵין מְקַבְּלִין אוֹתָם, שֶׁמֵּחֲמַת יִרְאָה הֵם עוֹשִׂים, וְזֶה לְשׁוֹן הָרַב. וְאֵינוֹ נָכוֹן, כִּי בְּעָרֵי הָעַמִּים הָאֵלֶּה אֲשֶׁר ה' אֱלֹהֶיךָ נֹתֵן לְךָ נַחֲלָה, בָּהֶם אָמַר לְמַעַן אֲשֶׁר לֹא יְלַמְּדוּ אֶתְכֶם, שֶׁאִם עָשׂוּ תְּשׁוּבָה אֵינָן נֶהֱרָגִין. וְכֵן אָמַר בָּהֶם (שמות כג לג) לֹא יֵשְׁבוּ בְּאַרְצְךָ פֶּן יַחֲטִיאוּ אֹתְךָ לִי כִּי תַעֲבֹד אֶת אֱלֹהֵיהֶם, הָא אִם עָזְבוּ אֶת אֱלֹהֵיהֶם מֻתָּרִין לֵשֵׁב שָׁם. וְזֶה הָעִנְיָן שֶׁעָשָׂה הַמֶּלֶךְ שְׁלֹמֹה שֶׁכָּתוּב בּוֹ (מלכים א ט טו-כב), וְזֶה דְבַר הַמַּס אֲשֶׁר הֶעֱלָה הַמֶּלֶךְ שְׁלֹמֹה לִבְנוֹת אֶת בֵּית ה' וְאֶת בֵּיתוֹ וְאֶת הַמִּלּוֹא וְאֵת חוֹמַת יְרוּשָׁלִָם וְגוֹ' כָּל הָעָם הַנּוֹתָר מִן הָאֱמֹרִי הַחִתִּי הַפְּרִזִּי הַחִוִּי וְהַיְבוּסִי בְּנֵיהֶם אֲשֶׁר נוֹתְרוּ אַחֲרֵיהֶם בָּאָרֶץ אֲשֶׁר לֹא יָכְלוּ בְּנֵי יִשְׂרָאֵל לְהַחֲרִימָם וַיַּעֲלֵם שְׁלֹמֹה לְמַס עֹבֵד עַד הַיּוֹם הַזֶּה וּמִבְּנֵי יִשְׂרָאֵל לֹא נָתַן שְׁלֹמֹה עָבֶד, וְהָעִנְיָן הַזֶּה כַּתּוֹרָה עֲשָׂאוֹ, כִּי קִבְּלוּ עֲלֵיהֶם שֶׁבַע מִצְוֹת, וְדָבָר בָּרוּר הוּא כִּי כֵּיוָן שֶׁנְּתָנָם שְׁלֹמֹה עוֹשֵׂי מְלַאכְתּוֹ גָּבְרָה יָדוֹ עֲלֵיהֶם וְיָכוֹל הָיָה לְהַחֲרִימָם, אֶלָּא שֶׁהָיָה מֻתָּר לְקַיְּמָם כְּמוֹ שֶׁכָּתַבְנוּ: וְטַעַם אֲשֶׁר לֹא יְלַמְּדוּ אֶתְכֶם לַעֲשׂוֹת כְּכָל תּוֹעֲבֹתָם אֲשֶׁר עָשׂוּ לֵאלֹהֵיהֶם, שֶׁיְּלַמְּדוּ אֶתְכֶם לַעֲבֹד הַשֵּׁם הַנִּכְבָּד בִּשְׂרֵפַת בְּנֵיכֶם וּבְנוֹתֵיכֶם וְכָל תּוֹעֲבַת ה' אֲשֶׁר שָׂנֵא, וַחֲטָאתֶם לַה' אֱלֹהֵיכֶם, שֶׁהוּא הִזְהִיר אֶתְכֶם שֶׁלֹּא תֹאמַר, אֵיכָה יַעַבְדוּ הַגּוֹיִם הָאֵלֶּה אֶת אֱלֹהֵיהֶם וְאֶעֱשֶׂה כֵּן גַּם אָנִי (דברים י"ב:ל'). וְהִנֵּה הַתּוֹרָה הִזְהִירָה (שמות כג לג) לֹא יֵשְׁבוּ בְּאַרְצְךָ פֶּן יַחֲטִיאוּ אֹתְךָ לִי כִּי תַעֲבֹד אֶת אֱלֹהֵיהֶם כִּי יִהְיֶה לְךָ לְמוֹקֵשׁ, וְהִיא אַזְהָרָה בַּעֲבוֹדָה זָרָה, כִּי אִם תִכְרֹת לָהֶם וְלֵאלֹהֵיהֶם בְּרִית יֵשְׁבוּ בְּאַרְצְךָ, וְרַבִּים מֵהֶם יְפַתּוּךָ לַעֲבֹד ע"ז. וְכָאן הוֹסִיף לְבָאֵר שֶׁלֹּא תְחַיֶּה כָּל נְשָׁמָה, כִּי אֲפִלּוּ הַיָּחִיד הַנִּשְׁאָר בֵּינֵיכֶם לַעֲבֹד לְךָ יַזְכִּיר לְךָ עֲבוֹדָתָם לֵאלֹהֵיהֶם, וְאוּלַי תִּתְפַּתֶּה אַתָּה לַעֲשׂוֹת כֵּן לַשֵּׁם הַנִּכְבָּד, וְתֶחֱטָא לְפָנָיו יִתְבָּרַךְ:
WHEN THOU DRAWEST NEAR UNTO A CITY TO FIGHT AGAINST IT, THEN PROCLAIM PEACE UNTO IT. “Scripture is speaking of a permissible war [rather than a war required by the Torah, such as the invasion of the seven nations of Canaan], as it is expressly stated in this section, Thus shalt thou do unto all the cities which are very far off from thee.” This is Rashi’s language. The Rabbi [Rashi] wrote this based on the Sifre where a similar text is taught: “Scripture is speaking of a battle waged of free choice.” But the intent of our Rabbis with reference to this verse [before us, was not to say that the requirement of proclaiming peace applies exclusively to permissible, but not to obligatory, wars; rather, their teaching in the Sifre] refers only to the later section wherein there is a differentiation between the two kinds of wars [i.e., in Verses 13-14 declaring that if the enemy insists on war, then only the men are to be killed, but the women and children are to be spared — that law applies only to a permissible but not to an obligatory war]. But the call for peace applies even to an obligatory war. It requires us to offer peace-terms even to the seven nations [of Canaan], for Moses proclaimed peace to Sihon, king of the Amorites, and he would not have transgressed both the positive and negative commandments in this section: but thou shalt utterly destroy them, and thou shalt save alive nothing that breatheth! Rather, the difference between them [i.e., obligatory and permissible wars] is when the enemy does not make peace and continues to make war. Then, in the case of the cities which are very far off, Scripture commanded us to smite every male thereof and keep alive the women and male children, but in the cities of these peoples [i.e., the seven nations of Canaan in the event they refuse the call to peace], it commanded us to destroy even the women and children. And so did our Rabbis say in the Midrash of Eileh Hadevarim Rabbah, and it is found also in Tanchuma and in the Gemara Yerushalmi: “Rabbi Shmuel the son of Rabbi Nachmani said: Joshua the son of Nun fulfilled the laws of this section. What did Joshua do? Wherever he went to conquer, he would send a proclamation in which he wrote: ‘He who wishes to make peace let him come forward and make peace; he who wishes to leave, let him leave, and he who wishes to make war, let him make war.’ The Girgashite left. With the Gibeonites who made peace, Joshua made peace. The thirty-one kings who came to wage war — the Holy One, blessed be He, cast them down etc.” And so indeed Scripture states with reference to all cities [including those of the seven nations], There was not a city that made peace with the children of Israel, save the Hivites the inhabitants of Gibeon; they took all in battle. For it was of the Eternal to harden their hearts, to come against Israel in battle, that they might be utterly destroyed. Obviously, if they had wanted to make peace, the Israelites would have made peace with them. It appears that regarding the terms of peace, there were differences [between what was offered the very far off cities and what was offered the seven nations], for, with reference to the distant cities, we ask that they make peace and become tributary to us and serve, but, regarding the cities of these peoples [the seven nations] we request of them peace, tribute and service, on the condition that they agree not to worship idols. Scripture does not mention it in this section, because concerning idolators, it has already given the prohibition, They shall not dwell in thy Land, lest they make thee sin against Me, for thou wilt serve their gods. It is possible that we must inform them only of the peace offer, tribute and service; after they are subject to us, we tell them that we execute judgment upon idols and their worshippers, whether individuals or the community. Similarly, that which is stated here, That they teach you not to do after all their abominations, and with reference to it the Rabbis said in the Sifre, “But if they repent [of their idol-worship] they are not to be killed” — this refers to the seven nations. The “repentance” is that they accept upon themselves the seven commandments in which “the sons of Noah” were commanded, but not that they must convert to become righteous proselytes. Now, in Tractate Sotah the Rabbis have said that “they [i.e., the Israelites upon coming into the Land] inscribed the Torah upon stones in seventy languages and that, below, they wrote, That they teach you not to do. However, [we deduce,] if the peoples were to repent, the Israelites would accept them.” Rashi explained this text as follows: “[This verse was written upon the stones below] to inform the nations that dwelled outside the border of the Land of Israel that they [i.e., the Israelites] were not commanded to destroy [populations] except for those [the seven nations] that dwell within the borders in order that they [the Canaanites] should not teach them their perverted practices. But as to those who dwell outside [the boundaries] we tell them, ‘If you repent, we accept you.’ Those who dwell within the Land we do not accept because their repentance was due to fear.” This is the language of the Rabbi [Rashi]. But it is not correct, for it was with reference to the cities of these peoples, that the Eternal thy G-d giveth thee for an inheritance — it was of them that he said that they teach you not thus indicating that if they do repent [thereby negating the fear that they may teach you] they are not to be slain. Similarly He said of them, They shall not dwell in thy Land, lest they make thee sin against Me, for thou wilt serve their gods, which indicates that if they abandon their gods they are permitted to dwell there. This is the project of Solomon concerning which it is written, And this is the account of the levy which King Solomon raised; to build the House of the Eternal, and his own house, and Millo, and the wall of Jerusalem etc. All the people that were left of the Amorites, the Hittites, the Perizzites, the Hivites, and the Jebusites, who were not of the children of Israel; even their children that were left after them in the Land, whom the children of Israel were not able utterly to destroy, of them did Solomon raise a levy of bondservants, unto this day. But of the children of Israel did Solomon make no bondservants. This project he did in accordance with the Law, for they accepted the observance of the seven commandments upon themselves. Now it is clear that since Solomon was able to draft them as his laborers, he had power over them and he could have destroyed them, except that it was permissible to let them live, as we have written. THAT THEY TEACH YOU NOT TO DO AFTER ALL THEIR ABOMINATIONS, WHICH THEY HAVE DONE UNTO THEIR GODS. The purport thereof is that they will teach you to worship the Glorious Name with the burning of your sons and daughters and every abomination to the Eternal, which He hateth, and so ye sin against the Eternal your G-d Who has warned you against saying, How used these nations to serve their gods? even so will I do likewise. Now the Torah warned them, They shall not dwell in thy Land, lest they make thee sin against Me, for thou wilt serve their gods, for they will be a snare unto thee, which is an admonition against idolatry, for if you make a covenant with them and their gods, they will dwell in your Land and many of them will entice you to worship the idols. He added here to explain that thou shalt save alive nothing that breatheth, for even one of them that remains among you to serve you, will remind you of the worship of their gods and perhaps you will be persuaded to do so to the Glorious Name and you will sin against Him, blessed be He.