He—may Allah have mercy on him—was asked:
A man died, having stipulated in his will that someone be paid in dirhams to pray on his behalf. What is the ruling?
He replied:
No one may perform an obligatory prayer on another’s behalf, whether for payment or otherwise, by agreement of the imams. Indeed, they agree that it is not permissible to hire someone even to perform voluntary prayers on one’s behalf, whether during one’s lifetime or after one’s death. How much less permissible, then, is hiring someone to perform obligatory prayers on one’s behalf!
The scholars differed only over whether a deceased person benefits when someone performs voluntary prayers without payment and dedicates their reward to him. There are two scholarly views on this. Likewise, if the deceased had vowed to pray but died before fulfilling his vow, may those vowed prayers be performed on his behalf? There are two views, both reported from Imam Ahmad.
However, the dirhams he bequeathed should be given in charity on his behalf, specifically to those who pray, so that the deceased receives a reward. He will also have a share in the reward of every prayer they perform with the help of his charity, without their own reward being diminished in the least. As the Prophet, may Allah bless him and grant him peace, said:
“Whoever provides a fasting person with food to break his fast will have a reward like his.”
And he said:
“Whoever equips a warrior has himself taken part in the campaign.”