All praise to Allah Swt and blessings on Prophet Muhammad peace be upon him His family and companions
Narrated Ali ibn AbuTalib: The Prophet (ﷺ) said: There are three
(persons) whose actions are not recorded: a sleeper till he awakes, a
boy till he reaches puberty, and a lunatic till he comes to reason.
Abu Dawud said: Ibn Juraij has transmitted it from Al-Qasim b. Yazid
on the authority of 'Ali from the Prophet (ﷺ). This version adds: "and
an old man who is feeble-minded."(Abi Dawud)
and
The Prophet(ﷺ) said: “Four types of people will be tested on the day
of judgement: a deaf man who cannot hear anything, a mad man, an old
aged man and a man who died during fatrah (a period of time when no
messenger was sent to people). The deaf man will say: “Oh Allah, Islam
came while I cannot hear anything!”. The mad man will say: “Oh Allah,
Islam came while the boys throw animals’ excrement on me!”. The old
aged man will say: “Oh Allah, Islam came while I can understand
nothing”. And the man who died during a fatrah will say: “Oh Allah, I
witnessed no messenger from You”. Then Allah takes a promise from them
to obey Him. Then He will command them to enter hell, and who enters
it will find it peace and cool, and who disobeys will be dragged to
hell” (Masnad Ahmad)
[Say], "Then is it other than Allah I should seek as judge while it is He who has revealed to you the Book explained in detail?" And those to whom We [previously] gave the Scripture know that it is sent down from your Lord in truth, so never be among the doubters.
And the word of your Lord has been fulfilled in truth and in justice. None can alter His words, and He is the Hearing, the Knowing.Quran(6-114,115)
One of the beautiful name of Allah Swt is AL-HAKAM (The Judge,The giver of Justice)
Allah Swt judges among people with complete fairness ,Truth and with justice.It would not be our duty on Judgement day to judge people,He is Maliki youm Ad din (King of the Judgement day),We are Abd (Servant) of Allah Swt.So The Servant has to surrender or submit himself to Allah Swt.Prophet Muhammad ﷺ once said “Who will be just if Allaah and His Messenger are not just?”.
So Our limited knowledge and intelligence is not enough to understand the descisions taken by Allah Swt.Allah Swt is just and fair to all.

Allah Swt and His Messenger knows best.