Joshua: Why God Punishes
The people of Canaan, whom God commanded to be killed, were being punished just like Sodom and Gomorrah was punished and like the world in Noah's day was punished. The whole earth had become corrupt in Noah's time with sexual sins (Genesis 6:11). The Canaanites too were indulging in degrading sexual sins and Satan worship. And so "the land itself vomited the inhabitants out", (Leviticus 18:24-25) Deuteronomy 9:4 and 18:10-12 give us clear reasons as to why God destroyed the Canaanites. Where there are polluting influences in any nation that defile and corrupt the land, the only thing to do is to punish such a nation by eliminating the people - lest their influence spread and corrupt others as well.
A God of love destroys some people just like a kind doctor amputates a man's foot when the gangrene in his foot is so severe that it threatens to destroy the whole body. If you saw a doctor sawing off somebody's leg, and did not understand the medicine, you would imagine that the doctor hated that man. But actually the opposite would have been true. The doctor was doing it in love. God also acts in love for the world when He cuts off certain people who would otherwise corrupt it. Wiping out the world's population at the time of the flood was act of love, so that the human race could be preserved without being totally controlled by demons (Genesis 6:2 - where the "sons of God" refer to God's creation - the angels fell). The apostle Paul once smote a man with blindness because he was leading another person astray (Acts 13:8-12). I have heard of cases of people who were smitten dead by God because they opposed a revival. So what we read of in Joshua is not the murder of the Canaanites, but rather a surgery to cleanse the land.
Many years earlier, when Abraham was living in Canaan, there were Canaanites there. But God did not destroy the Canaanites then. God waited for over 400 years, because , as He told Abraham, the Canaanites, were not "iniquities were not at the full, they were not ripe for judgement " at that time. (Genesis 15:16). We pluck fruit when they are ripe. God also waits for man's sins to become ripe for judgement, before he judges. He judged Sodom and Gomorrah when their sin was ripe. So too with the Canaanites.
After Israel had occupied Canaan for 700 years, when they committed the same sins as the Canaanites, God drove them out of the land too. The Assyrians came and captured them. 125 years later, when Judah, the southern kingdom, rejected the messages of God's prophets and ripened for judgement, God sent the Babylonians to destroy them too. God is not partial. Whether it be the Canaanites or the Israelites or the people of Judah, His standards are the same. If His people keep on violating His standards and ignoring His prophets, He performs the same surgery on them too. God does the same with us too. If God were to excuse you sin, it would prove he did not love you. If a father were to allow his children to live with their diseases, it would prove that he did not really love his children.