When you research this question on the internet, you’ll find that most answers address the example of the Jewish population, which had prophets and the scriptures to guide them to God. Almost none of the articles talk about what happens to those outside the Jewish faith, making their answers unsatisfactory.
If they had no prophets or scriptures, how were they saved? They were saved the same way as Abraham, before there were prophets or the scriptures: by believing God when God spoke to them. God spoke to Abraham, Abraham obeyed; God made a promise to Abraham; Abraham believed. Abraham was given righteousness through this simple faith. Salvation was an imputed right standing with God back then, not the Christian salvation we enjoy now. Abraham had very little knowledge about God; his faith was enough as God revealed Himself little by little over his life.
Romans 1-2 addresses this question further — what about those who did not believe, who never heard of God before Christ? The Bible tells us that God has made Himself known to all through His visible creation, according to Romans 1:19–20: “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.” (See also Psalms 19:1–4).
He has also revealed His moral code through the law written on our hearts, according to Romans 2:15, “They show that the work of the law is written on their hearts, while their conscience also bears witness, and their conflicting thoughts accuse or even excuse them.” when we excuse ourselves, we are acknowledging or covering up the wrong we know we’ve done (See Romans 2:12–16). Through this inner code we sense we have sinned in some way.
Those who pay attention to this and seek relief from God are greeted with grace as the Spirit leads them in faith to the mercy of God. It is this faith in God that saves them. Those who cover up their wrong move further from God. “He will render to each one according to his works: to those who by patience in well-doing seek for glory and honor and immortality, he will give eternal life; but for those who are self-seeking and do not obey the truth, but obey unrighteousness, there will be wrath and fury” (Romans 2:6–8).
There are reports of God reaching out to unbelievers today who haven’t heard of Jesus. One example is here: https://www.wnd.com/2014/11/rising-number-of-muslims-reporting-dreams-about-jesus/ This may be one of the ways God reached out to them in the past. He did speak to a pagan Pharaoh in dreams (Genesis 20:1–8).
What happens when they die? One orthodox answer is that they all died and went to a holding place, into which Jesus entered upon His death and preached the good news to them (Ephesians 4:9, 1 Peter 3:19). (Presumably this would help them know better the God who moved in their lives so long ago.) The rich man and Lazarus were put in such a place, but in separate compartments, as we learn in Luke 16:19–31.
Many articles on the web address this issue from the standpoint of the Jews who had the scriptures and the prophets to guide them. I hope this article answers the question for fully of how people came to faith who did not know God. GotQuestions.org gets it right in the video on this page: https://www.gotquestions.org/before-Jesus.html
Verses are from the ESV.
Like this article? Check out my books: https://www.stevehusting.com/doubtbusters/steves-books/