Being right with God is about trusting God to save us from sin.
Jesus died to save everyone from sin - those who came after him and those who came before. We have heard about God’s promise to save us on the Day of Judgement by Jesus’ death, and we are trusting that he will. In the same way, people in Old Testament times heard about God’s promise to save them by the one he had promised to send. They will be saved if they trust in the promise of the coming Saviour, Jesus.
If Jesus’ death is effective for you and me 2000 years after his death, then it can be effective for those who lived 2000 years before. It’s about trusting God to save us by the one he sends, rather than thinking we can get to God by ourselves without him.
We could say that they had in fact heard about Jesus before he came, they just didn’t know his name. It’s who he was and what he did that’s important, rather than whether we’ve met him or not (cos hey, we haven’t met him either!).
Have a look at this from Isaiah 53:3-6:
3 He was despised and rejected by men,
a man of sorrows, and familiar with suffering.
Like one from whom men hide their faces
he was despised, and we esteemed him not.
4 Surely he took up our infirmities
and carried our sorrows,
yet we considered him stricken by God,
smitten by him, and afflicted.
5 But he was pierced for our transgressions,
he was crushed for our iniquities;
the punishment that brought us peace was upon him,
and by his wounds we are healed.
6 We all, like sheep, have gone astray,
each of us has turned to his own way;
and the LORD has laid on him
the iniquity of us all.
They knew what the promised one was coming to do, they just had to trust God that He was going to save them through it - exactly what we need to do.