TT #322 · Parashas Shoftim · Seventh Aliyah · Passuk 20:18
So that they will not teach you to do according to all their abominations that they have done for their gods, and you would sin against the Eternal your God.
Torah Temimah points to Sifrei Devarim 200.
TT lemma: לְמַעַן אֲשֶׁר לֹא יְלַמְּדוּ אֶתְכֶם.
English: ‘So that they will not teach you to do’ – this is the reason for the herem.
Derash on the purpose of the herem (Sifrei) — the complete destruction is to prevent learning of abominations.
The seven nations are to be destroyed so that they will not teach Yisrael their abominable practices and cause them to sin against Hashem.