--- at this stage, the owner transfer deed to sheriff.
(k) if the property fails in foreclosure, then the lender has it back,
--- at this stage, the lender does not automatically gets the property, the lender must compete with other investors (if there is any) to bid the property back, the do get it 99% of the time, because they buy it back at book value, but if LTV is low, investors may bid in and it can be really profitable.
--- be very carefully here, any lien holder can foreclosure the property. a senior foreclosure will wipe out all junior lien holders. This means first mortgagee (most likely the bank) who forecloses and win it, will wipe out the second mortgage (HELOC)and all the mechanic's liens and other claims against the property, except taxes.
--- but the junior liens can not wipe out a senior lien, anyone win at this auction must pay off any senior lien to get a clean marketable title, many time, people win a auction and found they bought a secondary or maybe third lien.
--- Homeowner Associations (HOAs) liens are exceptions, their lien sometimes superior then the first mortgage, because many time, HOAs form before the house gets a mortgage, but it almost always include a subordination clause. A bank wouldn't lend money to buy a house with a HOA if the HOA could foreclose and wipe out their lien. So, the subordination clause says that a first lien mortgage is superior to the HOA's subordinate liens.
--- Tax liens are always first, IRS goes first, then state then local.