People often wonder about the eternal destiny of the unborn, babies, and those unable to intellectually understand the gospel. That question is a difficult one. Unfortunately, the Bible offers us no explicit answer. However, based on several passages, as well as an understanding of God's character and His dealings with men, we can develop a good idea of how He works in such situations.
Second Samuel 12:23 is one of the passages often quoted to imply that babies go to heaven. Though the verse doesn't explicitly say that, David clearly does expect to one day be reunited with his departed child. Since we know David is a believer whose destiny was heaven, we can infer that his hope of reunion means he expected his child to be in heaven. Thus, 2 Samuel 12:23 suggests strong evidence for a heavenly destiny of the unborn and children who die young.
If this were all we had to support our position, it would be admittedly less than stalwart. However, there are other evidences that point us to the same conclusion. First, the Bible clearly teaches that God cares deeply for children. Passages like Matthew 18:1-6 and 19:13-15 affirm the Lord's love for them. Those verses don't state that children go to heaven, but they do show God's heart toward children. He created and cares for children, and beyond that, He always accomplishes His perfect will in every circumstance.
The psalmist reminds us that God is "full of compassion and gracious, longsuffering and abundant in mercy and truth" (Ps. 86:15). He is the God who became flesh that He might carry our sins away by His death on the cross (2 Cor. 5:21). He is the God who will comfort Christians in heaven, for "He will wipe away every tear from their eyes; there shall be no more death; nor sorrow, nor crying. There shall be no more pain" (Rev. 21:4). We can be assured that God will do what is right and loving because He is the standard of rightness and love. Those considerations alone seem to be evidence enough of God's particular, electing love shown to the unborn and those who die young.
However, another point may be helpful in answering this question. While infants and children have neither sensed their personal sin and need for salvation nor placed their faith in Christ, Scripture teaches that condemnation is based on the clear rejection of God's revelation--whether general or specific--not simple ignorance of it (Luke 10:16; John 12:48; 1 Thess. 4:8).
Can we definitely say that the unborn and young children have comprehended the truth displayed by God's general revelation that renders them "without excuse" (Rom. 1:18-20)? They will be judged according to the light they received. Scripture is clear that children and the unborn have original sin--including both the propensity to sin as well as the inherent guilt of original sin. But could it be that somehow Christ's atonement did pay for the guilt for these helpless ones throughout all time? Yes, and therefore it is a credible assumption that a child who dies at an age too young to have made a conscious, willful rejection of Jesus Christ will be taken to be with the Lord.
For a tender and encouraging treatment of this sensitive subject, see John's book Safe in the Arms of God.