All perfect praise be to Allaah, the Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
Muslim sister, it should be noted that scholars differed about the validity of fasting on behalf of a dead person. Scholars who permitted it held that it would be permissible if the dead person was able to make up for these days before he died but he did not do so. In this case, it is recommended for his guardian to fast on his behalf. The guardian, according to the preponderant opinion of Muslim jurists, includes his relatives in general.
If a non-relative observes fasting on behalf of a dead person who granted him permission before his death, or his guardian permitted him, such fasting would be valid. Scholars differed about the validity of the fast observed by the non-relative who was not granted permission to fast. In his commentary on Saheeh Muslim, Imaam An-Nawawi said, "If a non-relative observes fasting on behalf of the dead person by permission of his guardian, it would be valid; otherwise, it would not according to the preponderant opinion."
If the Muslim remains sick until he dies and cannot make up for the days he missed, no one should observe fasting on his behalf.
In case fasting cannot be observed, only the days he broke his fast on should be made up for. If the number of days are not known, he is permitted to fast the days that he thinks are most likely sufficient to free the dead person from liability.
And Allaah Knows best.