Praise be to Allah.
If his memory is gone and his mind has changed so that he is not aware of things, then fasting and prayer are waived in his case, and he does not have to offer any expiation, because one of the conditions of being accountable is that one should be of sound mind.
The Prophet (peace and blessings of Allaah be upon him) said: “The Pen has been lifted from three: from the sleeping person until he wakes up, from the minor until he grows up, and from the insane person until he comes to his senses.” Narrated by Abu Dawood (4403), al-Tirmidhi (1423), al-Nasaa’i (3432) and Ibn Majaah (2041). Abu Dawood said: It was narrated by Ibn Jurayj from al-Qaasim ibn Yazeed from ‘Ali from the Prophet (peace and blessings of Allaah be upon him), and he added: “and the old man who is feeble-minded.”
This hadeeth was classed as saheeh by al-Albaani in Saheeh Abi Dawood.
It says in ‘Awn al-Ma’bood: “the old man who is feeble-minded”; this refers to when the mind becomes weak in old age. Al-Subki said: This implies that it is additional to the three (mentioned in the hadeeth), and this is correct. What is meant is the old man who has lost his mind due to old age, because an old man may become confused which prevents him from distinguishing things, and means that he is no longer accountable, but it is not called insanity and it does not say in the hadeeth “until he comes to his senses,” because in most cases he will not recover from this before he dies, and if he recovers for some of the time and comes back to his senses, then he is accountable for that time… End quote.
See: al-Ashbaah wa’l-Nazaa’ir by al-Suyooti, p. 212
Shaykh Ibn ‘Uthaymeen (may Allaah have mercy on him) said: Fasting is not obligatory unless certain conditions are met:
1- Being of sound mind
2- Being an adult
3- Being a Muslim
4- Being able to do it
5- Being a resident (i.e., not travelling)
6- Being free of menses and nifaas in the case of women
1 – Being of sound mind, the opposite of which is losing one's mind or reason, whether that is due to senile dementia i.e., old age, or an accident which has caused a person to lose his mind and awareness. This person does not have to do anything, because of his loss of reason. Like the one who has reached old age and reached the point of senility, he does not have to fast or feed the poor, because he has lost his mind. The same applies to one who is unconscious as the result of an accident or other cause; he does not have to fast or feed the poor, because he is not aware. End quote from Liqa’ al-Baab il-Maftooh (4/220).
He also said: The one who has lost his mind as the result of old age or an accident and there is no hope of recovery, is not obliged to fast, like the one who has reached a great age and become senile and can no longer speak properly. He is like a child and is not obliged to fast. The same applies to one who has had an accident and lost his mind in a way from which there is no hope of recovery. But if there is the hope of recovery, such as if he is merely unconscious, then he has to make up the fasts when he wakes up, but if he has lost his mind completely then he does not have to fast, i.e., if he does not have to fast then he does not have to offer the fidyah either. End quote from Sharh al-Kaafi.
What appears to be the case is that he does not have to pray or fast, and there is no need to feed the poor on his behalf instead of fasting.
And Allaah knows best.