A man said to the Messenger of Allah ﷺ, "My mother passed away suddenly, and I believe that had she been able to speak, she would have given charity. May I give charity on her behalf?"The Messenger of Allah ﷺ replied, "Yes."So he gave charity on her behalf.
أخبرنا محمد بن سلمة قال حدثنا ابن القاسم عن مالك عن هشام بن عروة عن أبيه
أن رجلا قال لرسول الله ﷺ إن أمي افتلتت نفسها وإنها لو تكلمت تصدقت أفأتصدق عنها فقال رسول الله ﷺ نعم فتصدق عنها
Bukhari narrated it in Wasaya, chapter on what is recommended for one who dies suddenly, that charity be given on his behalf, and the fulfilment of vows on behalf of the deceased, hadith no. 2760, from the hadith of Malik through this route, and it is also in Muwatta (Yahya): 2/760, and in Kubra, hadith no. 6476.