No answer can fully settle the death of a small child, because the ways of Hashem are hidden. The Shach reads the Hakhel teaching of little children as reward for those who bring them. Miriam taught Amram, in Mitzrayim, that such a child can merit the World to Come.