As Ann pointed out, Joshua was following Jehovah's express directions, which were intended to reduce long-term suffering in the region, and- if followed to the letter (which they were not)- would have prevented the widespread suffering that has perpetually troubled the region, to this very day.
I appreciate the fact that you are troubled by such accounts, that is not a bad indication, but is the sign of a considerate, sensitive spirit.
Making a competent judgment about the events surrounding the activity in ancient times, is not always easy, however. Looking around at events in our own time, and how they affect us, today, and what leads us toward agreeing with certain actions that take place, can help us, however.
In Joshua's day, a number of recorded events involving interventions by Jehovah, were present in Joshua's mind. Moving forward to the record at 2 Kings chapter 19, another example is recorded, when King Sennacherib of Assyria, laid siege to Jerusalem. 2 Kings 18:3 sates that King Hezekiah of Judah "kept on doing what was right in Jehovah's eyes", even though a series of disobedient kings, had previously caused many problems, in the region.
However, when the Assyrian king began trampling over his enemies, Hezekiah faltered, and made an alliance with a corrupt Pharaoh, in Egypt, rather than depending on Jehovah. Thus Jehovah did not act on Hezekiah's behalf, not until Hezekiah finally admitted his mistake, and humbled himself.
Jehovah remembered the good that King Hezekiah had done, and remembered that Hezekiah "was the one who removed the high places, smashed the sacred pillars and cut down the sacred pole" (2 kings 18:4) that had been used for wicked religious practices.
So once Hezekiah displayed a humble attitude, Jehovah responded, and: "On that very night, the angel of Jehovah went out and struck down 185,000 men in the camp of the Assyrians."- 2 kings 19:35
...and the king of Assyria fled for his life- which wasn't long, as his own sons murdered him, when he returned to Nineveh.
So Joshua had a relationship with a clean, understanding "Father" who had a long record of acting on behalf of those who followed his directions- unlike the nations that exist, today.
Since we are actually strangers to the people, times and mindsets that existed in Joshua's day... To better understand Jehovah, consider the encouragement and direction he gives to those living in the 21st-century. These are times we live in, thus we are aware of contemporary human attitudes and world events.
"And many nations will go and say: “Come, let us go up to the mountain of Jehovah, He will instruct us about his ways, And we will walk in his paths.”
"...Nor will they learn war anymore, For the mouth of Jehovah of armies has spoken."- Micah 4:2-7, Isaiah 2:2-5
It is very close to what we see at 2 Chronicles 20:17:
"You will not need to fight this battle. Take your position, stand still, and see the salvation of Jehovah in your behalf."