Ruling on doing the obligatory Hajj on behalf of someone who has lost his memory
Question

Is it permissible to do Hajj on behalf of a Muslim person who has lost his memory, with no hope of recovery?
Praise be to Allah.It is permissible to do Hajj on behalf of a Muslim who has lost his memory and on behalf of one who is insane, but this Hajj will not count as the obligatory Hajj for that person.
As for the obligatory Hajj, it cannot be done on their behalf during their lifetime, because of the possibility that the one who has lost his memory may regain it, and the one who is insane may regain his sanity, unless two trustworthy doctors confirm that there is no hope of his memory returning, in which case the obligatory Hajj may be done on his behalf.
An-Nawawi (may Allah have mercy on him) said: We have stated that if a person is sick, but there is hope that he may recover, it is not permissible to appoint someone to do Hajj on his behalf, and if he appoints someone to do it on his behalf during his lifetime then he dies, that does not count, according to the more correct of the two scholarly views.
Then he said: It may be found out whether the patient has no hope of recovery based on the view of two Muslims of good character and expertise.
Regarding the case of an insane person for whom there is still hope of recovery:
The author of ash-Shamil and our companions said: If Hajj became obligatory for him, then he became insane, no one should be appointed to do it on his behalf.
But if he dies, someone can do Hajj on his behalf.
If he appoints someone to do Hajj on his behalf when he is still alive, then he recovers, he must still do Hajj, according to scholarly consensus, as noted above regarding the sick person if he recovers…
We have noted above that our view, regarding a sick person for whom there is still hope of recovery, is that it is not valid for him to appoint someone to do Hajj on his behalf. The same applies to one who is insane: it is not valid for him to appoint someone to do the obligatory Hajj on his behalf. This is the view of Ahmad and Dawud.
Our companions narrated from Abu Hanifah the view that it is permissible in both cases. He said: That depends: if he recovers, then he must do Hajj himself, but if he dies, then what was done [by someone else on his behalf] is valid."(Al-Majmu‘  7/116).
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said:
There remains the issue of doing Hajj on behalf of one who is paralyzed – meaning one who is unable to move due to a chronic condition – is it valid to do Hajj on his behalf without his permission?
Our companions said: It is not valid to do it on his behalf without his permission.
What may be understood… – The commentator on the book said: There is a blank space in the two manuscripts of the book. Perhaps what is missing is: What may be understood is that that is permissible, because the Messenger (blessings and peace of Allah be upon him) likened it [Hajj] to a debt, and once a debt is paid off, the debtor is free of it, even if it is paid off without his permission. And Allah knows best. –
Moreover:
This applies so long as it is possible to seek his permission. When it is not possible to seek his permission, it is possible that Allah could cause the action of someone else to take the place of his own action with regard to obligatory duties and complying with religious commandments, just as the actions of someone else may take the place of his actions in other recommended deeds, and reward will still be attained, as noted above regarding the giving of reward to the dead. We have already established this principle."(Sharh al-‘Umdah – Kitab al-Hajj  2/192-193).
Shaykh Ibn Baz (may Allah have mercy on him) said: If the parent is insane or has lost his or her memory without being insane, there is nothing wrong with doing Hajj on his or her behalf, so the may do it as an act of kindness, whether the parent is his father or his mother, because Hajj is not valid if an insane person does it for himself; the Hajj of one who is insane or mentally disabled is not valid if he does it for himself. But if someone else does it on his behalf, there is nothing wrong with that, and he does not have to do the obligatory Hajj. If he reaches the age of puberty and is still insane, Hajj is not required of him, but if his son or his brother or someone else does Hajj on his behalf, there is nothing wrong with that and he will have the reward thereof."(Fatawa Nur ‘ala ad-Darb  17/73).
And Allah knows best.