Here’s how one scholar seeks to answer the hard questions about what the Israelites did to some of these nations:
“As Creator of all things and all human beings and as sovereign over all, God can do anything [He] wants with anyone and be right in doing so. … The ways of God are a mystery.
Since we will never completely understand [Him], we might as well relax with the questions in our minds. Isaiah 55:8-9 offers some consolation. According to the biblical picture of the Canaanites, these peoples were extremely wicked, and their annihilation represented God’s judgment for their sin. The destruction of the Canaanites was neither the first nor the last time God would do this. The differences between the Canaanites’ fate and the fate of humanity (except for Noah’s family) as described in Genesis 6-9 involve scale and agency. … God never intended for the Israelites to make the policy of herem [the total destruction] as a general policy toward outsiders. Deuteronomy 7:1 expressly identifies and thereby delimits the target peoples. The Israelites were not to follow these policies against Aramaeans or Edomites or Egyptians, or anyone else (cf. Deuteronomy 20:10-18). … The Canaanites suffered a fate that ultimately all sinners will face: the judgment of God. … God’s elimination of the Canaanites was a necessary step in the history of salvation. … Although the Canaanites as a whole were targets of God’s judgment, they had at least forty years of advance warning (see Rahab’s confession in Joshua 2:8-11).” — Daniel I. Block, The NIV Application Commentary: Deuteronomy (Grand Rapids, Mich.: Zondervan, 2012), pages 98, 99.