You might have heard this saying
"Religion was invented to keep masses under control"- Non Believer.
And also if you've read the Qur'an/Bible, you would understand the pattern of the examples given by the creator of the past who were too arrogant like of the Firaun(pharaoh), people of Noah(peace be upon him) etc.
And never would your Lord have destroyed the cities until He had sent to their mother(town or main center) a messenger reciting to them Our verses(warnings and guidance). And We would not destroy the cities except while their people were wrongdoers. (Qur'an 28:59)
These are the extreme cases and so became good examples for us in the religious books Old testament, Qur'an etc.
What about those who did not do anything wrong?
Then, (suppose) the creator did not send any prophets to them feeling "Oh! They're fine and don't need a warning(prophet)."
If at all they were fine, then fine, they'll be judged by the best of their deeds and will be punished as God wishes for their mistakes, and/or forgives as he wishes on the day of Judgement. As verily, the creator is All wise, and judges perfectly.
But, is it really possible that they don't receive a warner at all by resisting without doing anything wrong. I don't think so,
By time, Indeed, mankind is in loss, Except for those who have believed and done righteous deeds and advised each other to truth and advised each other to patience. (Qur'an 103)
The above verse has nothing to do with Islam, and is in general.
So, as time passes(generations pass), masses get out of control and need to be controlled.
Straight forward answer:
And for every nation is a messenger. So when their messenger comes, it will be judged between them in justice, and they will not be wronged. (Qur'an 10:47)
So, when a set of people in a nation are reminded and warned, they warn their next generation, and their next and so on until, the message gets lost and/or deviated as time passes and so does God come with a fresh and new messenger/warner revising the main message and modifying the verses/message which need to be modified according to the generation.
May the creator guide us all