If someone cosigned your mortgage or is a co-borrower on the loan, they'd be responsible for the debt if you die. Putting them as the beneficiary on a life insurance policy means they can use the payout to help settle the debt and keep the house.
If no one is responsible for the debt and your estate doesn't have enough funds to cover the mortgage, the lender may foreclose on the property. However, if someone inherits the home and wants to hold onto it, they're typically allowed to keep paying the mortgage. If this happens, a life insurance payout can help them cover the cost.
So even if your heirs aren’t legally responsible for the mortgage after you die, they may still benefit from a life insurance payout.