Someone asked, "Messenger of Allah, what about a child who dies young?"He replied, "Allah knows best what they would have done."
حدثنا عبد الرحمن قال حدثنا زائدة عن أبي الزناد عن الأعرج
قيل يا رسول الله فالمولود قال الله أعلم بما كانوا عاملين
Its isnad is sahih. It has already appeared at 1845 and in many other places. See also 9078. What is meant by the question is the children of disbelievers.