This is a really tough question to answer because I do not think the Bible gives us sufficient information with which to answer it. Certainly Jesus never discusses those who die without hearing the gospel message. Whenever Jesus discusses the judgment he refers to two categories of people: those who did the will of the master and those who did not. He does not mention those people who were not told what the will of the master was (see Matthew 25 for examples).
However this does seem to be a really important question. Even today with means of mass communication like television and the internet there are still people who have not heard about the gospel message or have only had a very cursory acquaintance with it. So there are undoubtedly a lot of people who have died who never heard the gospel message. It is reasonable to ask what will happen to them.
There are a number of options, many of which are related to various doctrinal positions. I will briefly describe the options below:
1. Those people who believe in the immortality of the soul will believe that everyone’s soul will go somewhere when they die. Some say there are only two options (i.e. heaven and hell); traditionally the Catholic Church said there were a few more (e.g. limbo, purgatory, etc.). According to this view, those who die in ignorance will still go somewhere when they die (because their soul is immortal). Some believe that more-or-less everyone, except the very worst sinners, will end up in heaven. I can’t see any biblical justification for this idea – it might be seen as wishful thinking. Others believe that only those who believe in Jesus can be saved (more on this below) and so most people will end up in hell. This would seem incredibly unjust and cruel to condemn those who never had a fair chance at obedience to an eternity of torment. Thankfully the concepts of the immortality of the soul and of hell are not biblical (see the answers to How is “soul” used in the Bible?, Why did Adam and Eve need immortal souls and when did they get them? and Does our soul or spirit go to heaven?) so we don’t need to try and make ourselves believe that a loving God would condemn the ignorant to eternal torment.
2. Another view is that as well as God’s revelation through Jesus (“special revelation”), God has also revealed himself through nature (“general revelation”) and that this general revelation gives people sufficient basis on which to know God, to know that they are responsible to God and to be rewarded with eternal life if they live up to that responsibility. This view is usually based on Romans 1:19-20, where Paul says:
For what can be known about God is plain to them, because God has shown it to them. For his invisible attributes, namely, his eternal power and divine nature, have been clearly perceived, ever since the creation of the world, in the things that have been made. So they are without excuse.
Since Paul says that all human beings are “without excuse” because the attributes of God are “clearly perceived” in creation then it would seem that all people are responsible for their actions. And if they are responsible then they can be judged. And if they can be judged then, in principle, they can be judged righteous.
The problem with this view is that Paul also says that all have sinned (Rom 3:23) and therefore all will die. Paul says salvation from death comes through faith in Jesus Christ, not through works. So Paul doesn’t seem to give us much confidence that someone who knows God only through general revelation can achieve salvation. To this we might add passages like Acts 4:12, which also indicate that only through Jesus can people be saved.
3. A third view is that people only become responsible by acquaintance with the gospel message (or, in the case of those before Christ, acquaintance with the Law and the prophets). According to this view, only those who have become responsible will be judged. Those who died in ignorance will stay dead and not be judged. This view comes from passages like Ecclesiastes 3:18, which suggests that humans (in their natural state) die like animals; it is only through coming to know God through his revelation that anyone has a chance of eternal life.
This view has some appeal because of its apparent justice. Intuitively we wouldn’t want to condemn someone for not following a rule they didn’t know about – that is unjust. In the same way we wouldn’t expect God to condemn those who died in ignorance for not following his rules that they didn’t know about. We might also think that, on this view, those who died in ignorance haven’t lost out because they didn’t know eternal life was on offer. I think one objection one might have to this view is that it seems strange (and perhaps unfair) for God to set up things in such a way that a chance occurrence (like the time and situation you are born into) will determine whether you get a shot at eternal life or not.
4. In contrast one might take the view that God possesses middle knowledge, that is, that God knows what would have happened in any given circumstance (including what you would have freely chosen to do in any given circumstance). If this is true then, it is argued, when God was setting up the world he created it in such a way that those who would freely respond to the gospel message were born in times and places when they would be exposed to the gospel message. According to this view those who live in ignorance of the gospel are those who would never have responded to the gospel message anyway and so God can justly judge them and deny them eternal life on the basis that if they had been exposed to the gospel message they would have rejected it.
This view depends on a philosophical issue, namely whether God possesses middle knowledge. I do not think the bible gives us sufficient data to answer this question independently of the conclusions of philosophy. And the bible does not give us any indication that those who live and die in ignorance would have rejected the gospel had they been given the opportunity. (Interestingly, this view is impossible to test because the only way to test how someone would respond to the gospel is to expose them to the gospel).
5. One final view is that those who do not have the opportunity to respond in this lifetime will be given an opportunity to respond at some point in the future. This might seem reasonable as it means everyone will be given an opportunity to be saved. However this is not something the Bible says anywhere.
In trying to decide which of these views is correct people will try to balance the justice and mercy of God against the specific claims of the New Testament that people are saved through faith in Jesus. Given the Bible is not explicit on this issue, we should be cautious about pre-empting the judgment of God and instead trust in his justice and mercy.