Abdullah bin Abbas reported,

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."

Azami 4764

Sahih

عن ابن عباس قال

جاء رجل إلى النبي ﷺ فقال: إن أبي مات ولم يحج أفأحج عنه؟ قال: أرأيت لو كان على أبيك دين أكنت قاضيه؟ قال: نعم، قال: فدين الله عز وجل أحق، حج عنه.

الأعظمي 4764صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Hajj
Chapter
Obligation of Hajj, its virtue, and its conditions
Section
Hajj on behalf of the deceased
Numbering
Jami al-Kamil 4764 (2nd edition)
Azami 4764