لَا يُكَلِّفُ اللَّهُ نَفْسًا إِلَّا وُسْعَهَا
Allah does not burden any human being with more than he can bear. (Surah al-Baqarah, 286).
When it comes to the issue of insanity, sometimes it is really quite clear that a person is insane, thus we can say that this person is not Mukallaf, meaning not legally responsible according to the law of Islam, and other times it is unclear.
The reality is only Allah (Most High) and the person knows what he is cognisant of, what he does understand and what he does not. Where he does have free will and where he does not. It can be very difficult for other people to know these things in such circumstances, and the situation described in the question certainly seems to be one in which it is difficult for others to understand.
Our duty is to advise the person while still bearing in mind that this person may not have volition regarding these actions. These can be exceedingly difficult situations to understand. Why is it that this individual can do certain things like a normal person and but engages in others that are totally unacceptable? It seems that the person does not have the mental capacity to understand what they are doing at times. However, this is not clear to us, so we will gently encourage the person to do the right thing in any given situation.
And Allah (Most High) knows best.
– Answered by Shaykh Noorud-deen (24.02.2021)