Banks generally don't extend HELOCs beyond a borrower's equity in the house, which is the fractional value of the house the borrower truly owns.
They are basically a flexible cash-out second mortgage.
> In the extreme, a home buyer borrows a million dollars to buy an expensive house, the economy tanks before the first payment, the borrower walks away, and the bank gets a house worth $400K.
You've just described ordinary mortgage risk, in no-recourse states. In recourse states, the bank can go after the borrower for the remaining balance of the loan ($600k). Generally if a bank was willing to lend $1 million to someone, they had reasonably high credit and cash flow at origination time (debt-to-income ratio, non-conventional jumbo loan). They may not get their $600k back, and in no-recourse states they will get $0 back, but that is priced in to the interest rate of the loan.