The term "holy war" does not appear in the OT. The closest in OT terminology that we get to ‘holy war’ is ‘Yahweh’s battles’ (1 Sam 25:28) and the lost poetry, the ‘Book of the Wars of Yahweh’ (Num 21:14). That so many people died in the conquest of Canaan and in subsequent battles always causes problems for students and their teachers. If the Israelites acted out of justifiable self-defense we could understand, but going on the offensive at Yahweh’s orders is another matter. To begin, we need to bear in mind that the Israelites sometimes used warrior terminology to describe God! (Ex 15:2; Ps 24:8). Many subtle references to Yahweh as warrior abound in the OT. For example, read the beginning of Ps 18. Yahweh is a standard/banner for going into battle (Ex 17:16). Yahweh fights on behalf of Israel (Ex 14:14; 1 Sam 11:14) and spurs the Israelites on to battle by sending a panic among them (1 Sam 11:7). It is not Israel’s strength that assures them of victory but God (Judg 7:1-8). Before battle, Israel consulted with God. Instruction about war is given in Deut 20:1-20; 21:10-14 and 23:9-14. Exaggeration came into play when composing and editing OT texts, and by comparing Joshua to Judges it is obvious that exaggeration has been used in Joshua. Jensen (God’s Word to Israel 118) writes about the exaggeration in the battle texts in Joshua. For example, he says that Israel practiced the ban (slaying everyone in defeated towns) as did her neighbors, but we find it in the most artificial parts of the narrative (10:28-40). The only challenge to the concept of war in the OT comes from the prophets. Their best-known statement on peace is in Isa 2:1-5 and Mic 4:1-3.
Turning to the NT, there is no condemnation of war on the lips of Jesus. He does express what is true for some at least, that those who live by the sword die by the sword (Matt 26:52). John the Baptist warned soldiers not to abuse their power (Luke 3:14). Read Eph 6:11-17 where we read that the war we wage is a spiritual war against sin. In 2 Cor 6:4 Paul writes of taking up spiritual weapons. The NT writers reinterpret holy war in a spiritual way.
However, we are still left with the problem of innocent people suffering violent deaths by the Israelites acting under God’s orders. In an attempt to come to terms with this difficult problem let us consider what some recent commentators have said. McKenzie writes, ‘Modern readers find the Israelite concept of the holy war a primitive type of morality; that it is, but it is doubtfully more primitive than the modern concept of war. Where the Bible relates the thought patterns of early Israel, it does not seem to rise above the thought of its time; and its conception of Yahweh as a warrior was an imperfect apprehension of His reality and activity.’ (Dictionary of the Bible 921). Hoppe (The Collegeville Pastoral Dictionary of Biblical Theology 162) says "The violence that marked the settlement of the Israelite tribes in Canaan is no more a theological problem than is the suffering that Jesus experienced. The violence by which Israel acquired its land was evil. Innocent people did die. What the Bible affirms is that despite this evil, the divine will achieves its purposes." We are still not very near solving the problem. However what helps me most is one of the statements above, that the Israelite “conception of Yahweh as a warrior was an imperfect apprehension of His reality and activity” i.e. that Israel misunderstood and misjudged God. It is a warning to us of the need for great discernment. It also teaches us to be humble. God was willing to work with imperfect human beings, so why can we not be humble and accept God’s use of the tools of the time?
Pprogressive moral development which could also help us to answer this question. Progressive moral development refers to our conscience disapproving of what the biblical authors take for granted that God approves but in time the error is seen. Another example might be Abraham being asked to sacrifice Isaac which now we would say was a case of mistaken conscience but at that time child sacrifice was common in the surrounding cultures.
To further help it is worth noting that in the war passages the attention is elsewhere. It is on the holiness of God and the purity of Yahwism. We also need to consider the theme of trust in God who acts for Israel. From the account of the Reed Sea onwards, a recurring theme is Yahweh fighting for his people. It is not holy war in any ordinary sense. This is seen, for example, in the orders to Gideon to reduce his numbers (Judges 7:1-8). The author’s attention is focused more on this issue of trust in God than on the question of innocent suffering. That is why the "spiritualization" of the holy war theme in the NT is such a natural progression, because the focus has always been on the "spiritual" themes of covenant and trust. In the end, we have to be humble and say that we do not fully understand. Everything is clear to God, not to us. As regards entering into war now, CCC 2309 outlines the conditions for using military force to defend oneself in a just war.