Praise be to Allah, and peace and blessings be upon the Messenger of Allah.
It is part of Allah’s perfect justice that He does not punish anyone until the proof has been established against them. Allah تعالى says:
﴿And We never punish until We have sent a messenger.﴾ [Al-Isra: 15]
Whoever receives the message of Islam correctly and the proof is established against them, then rejects it, has had the proof established against them. As for someone who never received the message at all, or received it in a distorted manner that did not enable them to understand its true nature, then their case is left to Allah تعالى, who knows His creation best and is the Most Just toward them.
A hadith narrated by Al-Aswad ibn Sari‘ رضي الله عنه mentions four categories of people who will present their case on the Day of Resurrection, including one who died during a period when no message had reached him. The hadith states that Allah تعالى will test them on the Day of Resurrection: whoever obeys will enter Paradise, and whoever disobeys will enter Hell. A number of scholars have authenticated this hadith.
Therefore, the basic principle is that a person who did not receive the message of Islam in a manner sufficient to establish the proof against them will not be punished merely for failing to believe in it during their worldly life. Rather, their matter is entrusted to Allah, and it has been reported that they will be tested on the Day of Resurrection.
This is part of Allah’s complete justice and mercy: He wrongs no one and does not punish a person before the proof has been established against them.
And Allah تعالى knows best.