1. First mortgage
oreclose on first mortgage,first mort bank take all the money, removes the first lien and buyer is stuck with all other liens and mortgage.
2. Second mortgage,
Foreclose on second mortgage,first in time, first in right, the money from foreclosure of second mortgage has to go to first mortgage, any left over would go to second mortgage. In your case the second mortage foreclosure cannot go through with 20K, it has to be over 200K (more than first mortgage) to make any money back.
3. Other Liens
For the same reason, mechanics lien and HOA lien rarely get foreclosed, because even if the house is sold, all senior mortgages takes priority over the mechanics and HOA to take the money.
Tax Lien. Only exception is tax lien. Tax lien takes first priority no matter when added. That's why on tax sale, buyer pays the tax and get the house, with ALL the mortgage REMAINING on the house.