Actually, if a property is foreclosed on and someone buys it on the Courthouse steps for more than is owed on the loans (plus costs to collect), the homeowner would get the difference. Lenders are not allowed to profit from foreclosures.
If no one bids on it at the Courthouse steps and the foreclosure is perfected, the house can be put on the market with a clean title. If it sells for more at this point, the lender would get all of the proceeds.