The issue of Tamlik (Transfer of Ownership)
The majority of Muslim jurists agrees that, even in the fixed eight categories of recipients, the condition for a valid payment of Zakah is that someone deserving should be given possession of Zakah property as its owner
If money was spent for the benefit of these very people - without having made them possess it as its owner - Zakah will remain unpaid.
This is the reason why the four Imams and the majority of Muslim jurists agree that it is not permissible to spend Zakah funds either on the construction of mosques, religious schools, hospitals and orphanages, or on other functional needs related to them.
There is no doubt the benefit of such projects does reach the poor, and all others who qualify as Zakah recipients, but the fact that these things have not passed on into their possession as owners makes Zakah invalid.
However, in orphanages where meals and clothes are given to orphans as being owned by them, then, it is possible to spend Zakah funds to the extent of this specific expenditure.
Similarly, the cost of the medicine supplied to the poor in need, by making them its owner, could be charged to the Zakah fund.
Likewise, Muslim jurists say that the coffin of an heirless dead body cannot be provided from Zakah funds, because the deceased is not capable of becoming an owner.
Yes, it is possible that the amount of Zakah is given to someone poor and deserving - and he, out of his free will, spends this amount on the coffin of the heirless deceased.
In the same manner, if this deceased person is in debt, this debt cannot be paid off from Zakah funds directly.
Yes, if the deceased person's inheritors are poor and deserve Zakah, then the amount can be given to them with the right to possess and own it. Once they become the 'Owner' of this amount, they can - out of their choice and free will - vacate the debt of the deceased from this amount.
Correspondingly, as pointed out earlier, the construction of public works does bring benefit for those who deserve Zakah, but because they have no right of ownership established into the arrangement, Zakah remains invalid.
All four Mujtahid Imams - Abu Hanifah, Shafi'i, Malik, and Ahmad ibn Hanbal - as well as the majority of Muslim jurists agree with these rulings.