قال عليه الصلاة والسلام : رُفِعَ الْقَلَمُ عَنْ ثَلَاثَةٍ : عَنِ النَّائِمِ حَتَّى يَسْتَيْقِظَ ، وَعَنِ الصَّبِيِّ حَتَّى يَحْتَلِمَ ،
وَعَنِ الْمَجْنُونِ حَتَّى يَعْقِلَ
رواه أبوداود في " السنن " (رقم/4403) وصححه الألباني في " صحيح أبي داود
He said peace be upon him : ( Pen is lifted for three: the sleeper
until wakes up, and the boy until he grows (adolescence) , and the
insane until be sane )
Narrated by Abu Dawood in " Sunan " (No. / 4403 ) and classed as
highly valid in " Saheeh Abi Dawood "
Note: classification of hadith or quotes said by prophet Mohammed.
According to investigation of religious clerks about who delivered and how delivered from the prophet till it written and conveyed to us now.
"Pen is lifted for three" : you can explain it as metaphor that those three cases their actions are not written or accounted. Means that they are not judged whatever they do until the condition in hadith met.
or explain it as if the writer-angels writing your works and actions into two classes good and bad (evil) inside a book, that book is your book which god will according to it, will judge you. Also the three cases, they are not judged whatever they do until the condition in hadith met.
(This explanation is still in a controversy even most Muslims take it)
The two explanation agree that they are not judged whatever they do until the condition in hadith happens.
And for the case of insane he will surely judged for works before he becomes insane and after he cures.
if he/she was born with intellectual disability or mental disease until he/she dies he/she will goes to heaven whatever he/she does while he/she was in that case of intellectual disability or mental disease.
Always remember god is fair and will not judge you with something you didn't or order something you can't do. And god is kind so be kind to the people specially the weak.
In life we should help them or donate to the organizations that take care of them, pray for them to cure and visit if you can.
Edited : Boy in hadith goes for girls and boys.