The lender has security over the property which is superior to the claim of the owner. In a bankruptcy, the title in the asset passes to a trustee in bankruptcy (not sure what the US equivalent is called), but the bankrupt may well stay on there as a 'debtor in possession', provided he pays the mortgage.
If he doesn't then he'll be out on his arse.
Debtor in possession financing is a huge business in the US in relation to the financing of assets which are in Chapter 11 - ie corporate insolvency.
If there is no equity in the property, then the bank may well decide to let the borrower stay on in the property, provided he pays the mortgage loan and interest.
But the property does NOT - unless US law is diametrically opposed to UK law - become that of the bankrupt free of mortgage, which appears to be what your are suggesting.
FWIW my first job was as an Examiner in Insolvency - working for the Official Receiver (an officer of the court) - and I've dealt at least a hundred individual bankruptcies, and a few dozen corporate insolvencies, with some interesting wrinkles. "Any economic unit can emit money. The serious problem is to get it accepted" Hyman Minsky
But the problem bankrupts in the UK have (or had - it may have been amended) is that the home belongs not to them, but to their trustee in bankruptcy. I saw cases where the trustee came back years later and sold the house over the (by now) former bankrupt's head, paying off the mortgage loan, and then making a distribution to creditors from the balance.
And of course the former bankrupt had to find somewhere else to live if he could not afford to buy the house back at the market price.
So the bankrupt would normally (if he was financially capable of paying the mortgage) arrange for (say) his wife, or a relative he trusts, to buy out the trustee's interest in the property, which might not cost that much if there is little equity.
It is true that in the UK, bankruptcy - alone - rarely, if ever, precipitates eviction. It is actually beneficial, rather than prejudicial, to the secured creditor.
I am reminded of the Jubilee Debt Campaign, where I was at first surprised to see the banks backing the campaign to relieve heavily indebted nations of debt. It took a little time to realise that if sovereign debt was forgiven, then there would be that much more free income to pay the bank debts.....D'oh...!! "Any economic unit can emit money. The serious problem is to get it accepted" Hyman Minsky