The Sefer HaChinukh presents the prohibition against marrying members of the seven nations, explaining that marriage creates deep attachment and can lead a person away from the true faith. It discusses the principle behind the commandment as well as its scope.
לֹא לְהִתְחַתֵּן בְּעוֹבְדֵי עֲבוֹדָה זָרָה – שֶׁלֹּא נִתְחַתֵּן עִם הָאֻמּוֹת. וְכָתַב הָרַמְבַּ"ם זִכְרוֹנוֹ לִבְרָכָה (מאיסורי ביאה יב א) לֹא עִם שִׁבְעָה עֲמָמִים וְלֹא עִם שְׁאָר הָאֻמּוֹת, שֶׁנֶּאֱמַר (דברים ז ג) וְלֹא תִתְחַתֵּן בָּם. וְעִנְיַן הַחַתְנוּת הוּא, שֶׁיִּתֵּן בִּתּוֹ לִבְנוֹ אוֹ בְּנוֹ לְבִתּוֹ, וּכְמוֹ שֶׁבֵּאֵר הַכָּתוּב (שם) בִּתְּךָ לֹא תִתֵּן לִבְנוֹ וּבִתּוֹ לֹא תִקַּח לִבְנֶךָ. וְכָל שֶׁכֵּן הַמִּזְדַּוֵּג עִמָּהֶם, שֶׁהוּא בְּעַצְמוֹ בִּכְלַל הָאִסּוּר, וְאָמְרִינַן בְּמַסֶּכֶת עֲבוֹדָה זָרָה (לו, ב) דֶּרֶךְ חַתְנוּת אָסְרָה תּוֹרָה, וְאַף עַל פִּי שֶׁהַכָּתוּב הַזֶּה דְּלֹא תִתְחַתֵּן בְּשִׁבְעָה עֲמָמִים הוּא דִּכְתִיב וּבְגֵרוּתָן דַּוְקָא, וְהָכִי מַשְׁמַע לְהוּ לְרַבָּנָן שֶׁאָמְרוּ בַּגְּמָרָא (יבמות עו, א) בְּגֵרוּתָן אִית לְהוּ חַתְנוּת, בְּגַיּוּתָן לֵית לְהוּ חַתְנוּת, בַּמֶּה שֶׁחָזַר הַכָּתוּב בִּתְּךָ לֹא תִתֵּן לִבְנוֹ וּבִתּוֹ לֹא תִקַּח לִבְנֶךָ יְרַבֶּה שִׁבְעָה עֲמָמִים וְכָל שְׁאָר הָאֻמּוֹת בָּאִסּוּר אַף בְּגַיּוּתָן, אֲבָל שִׁבְעָה עֲמָמִין נֶאֶסְרוּ אַף בְּגֵרוּתָן לְפִי שֶׁהָיוּ עִקַּר עֲבוֹדָה זָרָה וִיסוֹדָהּ הָרִאשׁוֹן, וּשְׁאָר עֲמָמִין מֻתָּרִין בְּגֵרוּת, וְאִסּוּר זֶה יִהְיֶה דַּוְקָא כְּשֶׁהוּא מְיַחֲדָהּ לוֹ לְאִשָּׁה, אֲבָל הַבָּא עַל הַגּוֹיָה דֶּרֶךְ מִקְרֶה, כְּאָדָם שֶׁבָּא עַל זוֹנָתוֹ שֶׁלֹּא בְּפַרְהֶסְיָא, אֵין בָּזֶה אֶלָּא אִסּוּר דִּבְרֵיהֶם, וְהוּא אִסּוּר נשג"ז (נדה, שפחה, גויה, זונה), הַמֻּזְכָּר בַּעֲבוֹדָה זָרָה (שם). מִשָּׁרְשֵׁי הַמִּצְוָה. לְפִי שֶׁרֹב הֲמוֹן הָעָם, דֶּרֶךְ טִפְּשׁוּת יִמָּשְׁכוּ אַחַר עֲצַת נְשׁוֹתֵיהֶם, וְאִם יִשָּׂא אָדָם בַּת אֵל נֵכָר תִּמְשְׁכֵהוּ לַעֲבֹד עֲבוֹדָה זָרָה, וְעוֹד כִּי גַּם בָּנֶיהָ הַנּוֹלָדִים מִמֶּנּוּ תְּגַדֵּל לַעֲבוֹדָה זָרָה, וְאוֹי לוֹ לַפּוֹסֵל אֶת זַרְעוֹ.
To not marry with idolaters: That we should not marry with the nations — and Rambam, may his memory be blessed, wrote (Mishneh Torah, Laws of Forbidden Intercourse 12:1), “Not with the seven nations and with the other nations” — as it is stated (Deuteronomy 7:3), “You shall not marry with them.” And the matter of marriages is that he give his daughter to [the idolater’s] son or his son to his daughter, and as the verse elucidates, “you shall not give your daughter to his son, and his daughter you shall not take for your son.” And all the more so one who mates with them [himself], as he himself is included in this prohibition. And we say in Tractate Avodah Zarah 36b [that it is] by way of marriages that the Torah forbade. But even though this verse of “You shall not marry them” is written specifically about the seven nations and in their being converts — and so is it understood by our Rabbis, who said in the Gemara (Yevamot 76a), “In their being converts, they have marriages, in their being gentiles, they do not have marriages” — in that which the Scripture restates [that which is already understood], “you shall not give your daughter to his son, and his daughter you shall not take for your son,” it [comes to] include the seven nations and all of the other nations even in their being gentiles. But the seven nations are forbidden even in their being converts because they were the main [source] of idolatry and its first foundation, whereas the other nations are permitted by conversion. But one who has sexual relations on occasion, such as a man who has sexual relations privately with his harlot — this is only a rabbinic prohibition, and it is the prohibition of nashgaz (the Hebrew initials of the four types of women included: menstruant, maidservant, gentile, harlot) mentioned in Avodah Zarah 76a. It is from the roots of the commandment [that it is that] since most of the masses — in their stupidity — are drawn after the counsel of their wives, if one marries the “daughter of a foreign god,” she will draw him to worship idolatry. And also because her children that are born from her will be raised towards idolatry. And woe to the one who disqualifies his seed.