Deuteronomy 20:18
That they teach you not to do after all their abominations, which they have done unto their gods; so should ye sin against the LORD your God. That they teach you not to do after all their abominations, which they have done unto their gods; so should ye sin against the LORD your God.
Moses rehearsed these laws to Israel just before crossing the Jordan into the promised land, and this command belongs to that rehearsal of God's law and its importance. It stands within his recounting in Deuteronomy 3 to 22 of Israel's experiences and God's guidance. There it joins his constant appeal for Israel to serve the Lord, to turn away from the sins that wrecked the surrounding nations, and to reveal Him as the sole ground of their greatness and continuance. It joins the precepts of the law to gracious promises, showing the excellent working and superiority of God's laws amid the conditions surrounding Israel. The command warns Israel not to imitate or adopt the abominable worship practices of the nations, because doing so would cause them to sin against the Lord.
To keep the nations from teaching Israel those abominations, the Canaanites as enemies of God were to be utterly destroyed. Israel thus served as an instrument of judgment against nations whose iniquity had become full. Their destruction was a merciful judgment because their wickedness had become hopeless, for God waited four hundred years until the iniquity of the Amorites was full before bringing war upon them.
The commanded destruction was meant to impress Israel with God's abhorrence of idolatry and to preserve them in the true religion, while demonstrating the powerlessness of the heathen gods and the power of Jehovah. The conquest is connected with the Canaanites' cruel worship, including human sacrifice like that later seen in Aztec rites, which was invoked as a scriptural precedent for conquest. Those who show the same spirit as the Canaanites likewise face destruction.
Typologically, just as the sun, moon, and stars in the wilderness could draw the church away to worship other gods, so the warning reaches beyond Israel. It teaches that the Christian church must not be drawn away by such attractions into false worship. In particular it must not be drawn into worshiping a power that sets itself forth as God.