That’s a common misunderstanding, I actually was confused about this myself for a while. You are right that if someone dies in mortal sin they go to hell, because they’ve rejected God. It seems like if people never knew then they couldnt be held responsible. So it seems like preaching the Gospel would make things worse; here they were blissfully ignorant and going to heaven, but now you told them about Jesus so now they have no excuse. If that’s the case, why does the Church spend so much effort at evangelizing? Seems redundant.
Here’s the key:
First, the Church doesn’t teach that people who are ignorant are automatically going to heaven, just that there is a POSSIBILITY of salvation. Plus, it’s not just ignorance, but invincible ignorance, which means your not responsible for your ignorance.
But in order to get to heaven you still have to cooperate with the grace and light God has given you, and you have to be trying to live a good life, and seeking God. All of that is harder to do without the truth and without the sacraments.
One analogy I like for the Church is the image of a ship, Catholics are those in the ship, other non-catholic Christians are holding onto the ship but on its outside. And non Christians are kinda floating on a life ring. It’s not impossible for them to make it to the same place those in the ship are heading. But it’s a lot harder, there’s more of a chance they’ll get off course, or they’ll be thrown off by the waves and storm. By the same token, those in the ship could become careless and lax and fall out. But still, it’s just common sense to be in the boat, it’s safer and more secure. Therefore, we who are in the boat should be throwing a rope and trying to bring as many people as we can into the ship. It may have a lot of smelly sailors on board, but at least we know it won’t sink.
Also, with sin, just because someone might not be culpable of mortal sin, it’s still harmful to them. Sin is never a small deal. God doesn’t forbid this stuff for no reason, it’s because it’s fundamentally contrary to what were made for and hurts us and everyone around us.
Another analogy

what if you saw someone driving a Mercedes Benz into a wall, and the engines overheating, the tires are going bald, and they’re going nowhere and destroying their car. But they legitimately have no clue that they’re misusing the gift of driving. They’re blissfully ignorant. Would you just stand there and go “well they don’t know any better or different, better just to leave them be”? No. You’d show how they’re meant to use a car, teach them, help fix the car, and then they can actually start going somewhere.
Anyways, I hope that helped clear things up a little!