1 Sam 15:2-3; Deut 20:16-18
Why did God order the genocide of the Amalekites and the Canaanites including the children ? On the surface, it will seem that God is not merciful though just.
We must first remember that God’s ways are higher than our ways and His thoughts are higher than ours. Is 55:9, Rom 11:33-36. We must trust that He is good as well as just.
Because King Saul did not obey God’s commandment to annihilate the Amalekites, decades later, the survivors were able to take King David’s family captive. This would never happen if King Saul obeyed.
And same for Canaanites which God forewarned that they would teach the Israelites detestable things such as worshipping idols and sinning against God. God was preventing future greater evil by giving such an order.
To judge such tribes without any righteous person seems fair but the difficult part of God’s command is the killing of children and infants.
But if the lives of the children and infants end before a certain accountable age to know right and wrong and they are saved, it will be a different matter altogether and in fact, it reveal God is merciful on the contrary. As seen in the case of the Amalekites, by sparing the young, they still grew up to be as wicked as their forefathers.
Two passages seem to suggest this possibility.
2 Samuel 12:22-23
22 He said, “While the child was still alive, I fasted and wept, for I said, ‘Who knows whether the LORD will be gracious to me, that the child may live?’ 23 But now he is dead. Why should I fast? Can I bring him back again? I shall go to him, but he will not return to me.”
14 Therefore the Lord himself will give you a sign. Behold, the virgin shall conceive and bear a son, and shall call his name Immanuel.15 He shall eat curds and honey when he knows how to refuse the evil and choose the good.
When the life of King David’s son was ended, King David assuredly said that he would go to him in future implying that he will see his son in heaven.
In the other passage on the sign of Christ given to Israel by the prophet Isaiah, there was an accountable age mentioned by which he would know how to refuse the evil and choose the good.
So I strongly believe that all children and infants who die before the accountable age will get to go to heaven by the grace and mercy of God.
Similarly those, who suffer from mental illness before the accountability age and are unable to how to refuse the evil and choose the good, will get to heaven by the same line of reasoning.