The short answer is that God commanded them to do so.
When the Lord your God brings you into the land that you are entering to take possession of it, and clears away many nations before you, the Hittites, the Girgashites, the Amorites, the Canaanites, the Perizzites, the Hivites, and the Jebusites, seven nations more numerous and mightier than yourselves, and when the Lord your God gives them over to you, and you defeat them, then you must devote them to complete destruction. You shall make no covenant with them and show no mercy to them. (Deut 7:1-2)So the Israelites did what they did to the Canaanites at God’s command. I should be quick to point out, however, that this was not to be Israel’s usual policy in war—the wholesale slaughter of every man, woman, and child.
In Deuteronomy 20 we read that whenever there was a just occasion to go to war and to lay siege to an enemy city outside the land of promise, Israel was to give the city terms of peace. And if the city accepted the terms—all well and good. But if not—if the city made war against them, then Israel was to wage war in turn. And when they defeated them, Israel was commanded to “put all their males to the sword, but the women and the little ones” were to be spared (Deut. 20:13-14).
This was how things were to be handled outside of the land of Canaan. As for cities within Canaan, however, no terms of peace were to be offered. The Canaanites must either flee or perish…every last one of them—men, women, and children.
We should remember that God himself also on occasion wiped out entire cities, women and children along with the men. Remember Sodom and Gomorrah, Admah and Zeboiim, the four cities of the plain that God destroyed with a rain of fire and brimstone in Genesis 19. The entire population of these cities was destroyed, including the women and children. Not only this, but God also once destroyed the entire world by means of a flood. He wiped out every man, woman, and child on the face of the earth, except for Noah and his family.
God has the right (because he is God) to exact vengeance on evildoers in whatever way he sees fit. And we can be sure that all of God’s ways are just and holy and true.
The wickedness of the Canaanites is hinted at in God’s original promise to Abraham concerning the land. God told Abraham that he was going to give him and his descendants the land of Canaan, but not just yet, because “the iniquity of the Amorites is not yet complete” (Gen. 15:16). In other words, the sin of the Canaanite tribes was ripening for judgment. The magnitude of their sin is evident from a number of passages in the Bible, as well as from other historical sources. The Canaanites were guilty of all kinds of abominable practices, things like human sacrifice (even the sacrifice of their own children) and other forms of violence. They were guilty of all manner of sexual perversions, as well, things for which the Lord says, “the land vomited out hits inhabitants” (Lev. 18:25).
Now someone might ask, “But couldn’t the Lord have commanded the Israelites to have put the Canaanite men to death, and to spare the women and children?” Certainly, he could have. But apparently he deemed the women to have been worthy of death, as well as the men.
“But what about the children?” We can look upon the slaughter of the children as a punishment of the parents. God has at times threatened to punish evildoers by killing their children. This is what is meant in the second commandment when God says he will visit the iniquity of the fathers on the children to the third and the fourth generation of those who hate him (Ex. 20:5).
Another thing to consider is the fact that allowing the Canaanites to live would only serve to tempt Israel to imitate their ways (Ex. 23:23-33; 34:11-16; Deut. 7:1-2; 20:10-18).
Finally I should mention that the conquest of the land of the Canaan, with the command to exterminate the Canaanites, was a unique situation in the history of the world. There is no justification to use this as a basis for the concept of total warfare—that is, making war against an entire population. When a Christian is called upon to wage war, he should make every effort avoid civilian casualties.