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.
When Hajj becomes obligatory on someone and he passes away before performing it without stating in his will that it should be performed on his behalf, then the Hanafis, Maalikis, and other scholars who adopted their view held that it is not obligatory to deduct the Hajj costs from the estate to be performed on behalf of the deceased because Hajj is a physical act of worship that is waived by the person’s death. On the other hand, the Hanbalis, Shaafiʻis, and other scholars who adopted their view maintained that it is obligatory in this case to deduct the Hajj costs from the deceased’s estate (before the division of the estate) and pay them to someone to perform Hajj on behalf of the deceased. Ibn Qudaamah mentioned the different opinions and their supportive evidence in detail as follows:
“When Hajj becomes obligatory on someone and that person dies before performing it, then the amount needed to perform the Hajj and ʻUmrah on his behalf should be deducted from his estate, whether he did not carry out that obligation out of neglect or due to any other reason. This view was adopted by Al-Hasan, Taawoos, and Ash-Shaafiʻi. Abu Haneefah and Maalik, on the other hand, held the view that the obligation of Hajj is waived by death. If the deceased stated in his will that the Hajj costs should be deducted to be performed on his behalf, then the amount deducted should not exceed one-third of the estate. This position was adopted by Ash-Shaʻbi and An-Nakhʻi because Hajj is a physical act of worship that is waived by death, just like prayer. However, our evidence is that Ibn ʻAbbaas narrated that a woman came to the Prophet, sallallaahu ʻalayhi wa sallam, and said, 'My father passed away before performing Hajj (should I perform it on his behalf)?' He, sallallaahu ʻalayhi wa sallam, said, 'Perform Hajj on your father's behalf.', [An-Nasaa’i] He (Ibn 'Abbaas) also narrated that a woman vowed to perform Hajj but then died. Her brother came to the Prophet, sallallaahu ʻalayhi wa sallam, and asked him about that, he said, 'See, if your sister had been in debt, would you have paid her debt?' He said, 'Yes.' He, sallallaahu ʻalayhi wa sallam, said, 'Then, fulfill the right of Allaah, for He is more deserving that His rights should be fulfilled.' [An-Nasaa’i]...” [Al-Mughni]
As for voluntarily performing Hajj on behalf of the deceased, whether Hajj was obligatory on him or not, Ibn Qudaamah wrote:
“It is impermissible to perform Hajj or ʻUmah on behalf of a living person except with his permission regardless of whether Hajj or ʻUmah are deemed obligatory on him or voluntary, because performing such acts of worship on behalf of the adult Muslim must be done with his permission, just like it is the case with zakah. As for the dead person, it is permissible to perform Hajj on his behalf without his permission whether it was deemed obligatory on him or not because the Prophet, sallallaahu ʻalayhi wa sallam, commanded performing Hajj for the dead person, knowing that there was no way to get his permission. That which is permissible when obligatory is also permissible when voluntary, such as charity. Hence, when someone performs any act of worship on behalf of the deceased other than what he was asked to perform on his behalf, such as Hajj instead of ‘Umrah or ʻUmrah instead of Hajj, such acts of worship are valid and benefit the deceased because they may be performed on his behalf without his permission. However, the permission of a living person is required in such a case (when performing such acts of worship on his behalf). In this case, such acts of worship performed on behalf of a living person without his permission count for the person who performed them and not the living person to whom they are dedicated because they cannot be performed on behalf of the living person except with his permission; so they count for the person who performed them like is the case with the fidyah (expiation) for fasting.” [Al-Mughni]
If someone, be it a relative or not, wanted to perform Hajj on behalf of the deceased and Hajj was deemed obligatory on this dead person, then there is no harm if he performed obligatory Hajj on behalf of him. If Hajj was not obligatory on the deceased, then the person performing Hajj on his behalf should intend performing a voluntary Hajj on behalf of this dead person.
Allaah knows best.