Problem: God is depicted in the Bible as a God of mercy and compassion, freely forgiving those who turn to Him (Ps. 94:18–19; Lam. 3:22; James. 5:11; 2 Peter 3:9). By vivid contrast, this text informs us that God commanded the seemingly merciless slaughter of innocent Amalekites—men, women, and children. Why?
Solution: The Amalekites were far from innocent. In fact, they were utterly depraved. What is more, they desired to destroy Israel (v. 2), God’s chosen people, the channel of His redemptive plans for all humankind (Gen. 12:1–3). The act of their total destruction was necessitated by the gravity of their sin. Otherwise, some hard core remnant might rise to resume their hateful act toward God’s people and plan.
As to the question about the innocent children, several observations are relevant. First, we are all born in sin (Ps. 51:5) and deserve death (Rom. 5:12). Everyone will eventually be taken by God in death—it is only a matter of when (Heb. 9:27). Second, God is sovereign over life and reserves the right to take it when He will (Deut. 32:39; Job 1:21). Third, all children who die before the age of accountability are saved (see comments on 2 Sam. 12:23). Hence, the act by which God took the children is far from merciless (see also comments on Josh. 6:21).