A man came to the Prophet ﷺ and said, "My father has died without performing the Hajj. Shall I perform it on his behalf?"He replied, "Tell me, if your father had a debt, would you pay it off?"The man said, "Yes."He said, "Then the debt owed to Allah is more deserving of being paid. Perform the Hajj on his behalf."
جاء رجل إلى النبي ﷺ فقال: إن أبي مات ولم يحج أفأحج عنه؟ قال: أرأيت لو كان على أبيك دين أكنت قاضيه؟ قال: نعم، قال: فدين الله عز وجل أحق، حج عنه.
Tahawi narrated it in Sharh Mushkil Athar (2542), Ibn Hibban (3992), and Tabarani in al-Kabir (12/15), all of them through routes from Ubaydullah bin Amr, from Amash, from Muslim al-Batin, from Saeed bin Jubayr, from Ibn Abbas, who related it. Its chain of transmission is sahih. These hadiths from Ibn Abbas are to be understood as referring to multiple occurrences.