How do we cope with passages in the Bible, where God commands the genocide of various peoples?
The first point to make is that before the formation of scripture, the general guidance to Yahwists was, ‘Know YHVH’ (cf Jer 31:34, 1Chron 22:19, Hos 2:20, 6:3; in Yahwism, YHVH is a knowable God). This principle still stands – God’s commandment was not rescinded once the Bible was written. Therefore, for anyone who still follows the pre-Exile Israelite faith, we interpret scripture through our knowledge of the living character and personality of YHVH.
This is not the case for religious fundamentalists, who interpret God through scripture (as if God were a long-dead character in history, who can only be studied by reading books). Studying God this way, God becomes a fossilised creation of scripture, rather than scripture being a creation of those who are inspired by the living God. For fundamentalists, scripture is more important than God, whereas for us, our living God is more important than scripture; the Bible is not our god. To place the Bible on an equal footing with God is idolatry (specifically bibliolatry, idolising scripture to the extent that its authority is equal to that of God’s).
God is love, justice, wisdom, mercy, compassion – you can find copious biblical passages to support these characteristics. This was the personality of YHVH since the beginning – creation itself was an act of love. As a parent looks down with a loving gaze at their newborn child, so God looked at God’s creation with love – that is what the phrase, ‘God saw that it was good’ implies.
So when anything appears in scripture that does not fit with our knowledge of YHVH’s character, then such episodes have been created by human beings.
This leads us to our second point. Many stories in the Bible were written down long after the events they portray. Most of the Hebrew Bible got its final edit after the Jews returned from Exile in the 6th century BCE. At that time, there were no longer any Canaanites, so the writers thought that the Israelites must have killed all the Canaanites, and furthermore, that God must have given this instruction, otherwise surely the Israelites would not have done it.
However, throughout the Bible, we have hints that the Canaanites still existed right up until the period before the Exile. Before that, some Canaanites joined the Israelites and became Yahwists.
Also, when the northerners and southerners were taken into exile, the Assyrians and Babylonians took the Canaanites and Philistines into exile too, and they were all scattered amongst the other peoples of the empire – this was a deliberate policy to ensure that the exiled peoples did not have the sufficient concentration of population to revolt. So it was the Assyrians and the Babylonians who caused the Canaanites and Philistines to go extinct, not the Israelites.
Basically, anything that portrays God as a genocidal tyrant is the result of human guesswork, and how the ancients saw and understood the world, because YHVH would not behave like that. As you said, we have to understand such passages in scripture from the point of view of the people who lived at that time. They saw the world differently – their world was plagued by wars and invasions, and so they wrote stories that supported their people against those who caused them suffering. Such stories tell us more about what the ancient Israelites were going through, than it does about God.