The complete destruction of Ai and its inhabitants was a command from the Lord (Joshua 8:1–2; Deuteronomy 20:16–18). According to Leviticus 18:24–30, the land had become unclean as a result of the sin of the Canaanites. The people of Israel were used by the Lord as an instrument of his justice to cleanse the land (Genesis 15:16). This was done to ensure that the Israelites would not be tempted to idolatry (Deuteronomy 20:16–18) and the other abominable practices for which the people of Canaan were known (Leviticus 18:1–30).
24 When Israel had finished killing all the inhabitants of Ai in the open wilderness where they pursued them, and all of them to the very last had fallen by the edge of the sword, all Israel returned to Ai and struck it down with the edge of the sword.