A mortgage, especially a purchase money mortgage (i.e. a mortgage you used to buy the home) typically has priority over a lien. That means that when the house is foreclosed upon, then sold, first some of the sale proceeds are used to pay off administrative costs of the sale; then the proceeds are used to pay off the mortgage; and only if the mortgage is paid in full will any remaining money be applied to the lien. The bank does not need to pay the lien in order to sell; instead the lien may be paid off after the bank sells, but only if the house sells for enough. If it does not, the lien holder may still seek the money from you.