Foreclosure normally wipes out debts that are junior to the foreclosed note where the property secures the lien. For example, if a property is foreclosed by the second lien-holder, the first lien remains intact and the conveyance is subject to the first mortgage. Say a homeowner's association foreclosed for non-payment. Generally, their claims are subordinated to the first and second liens and so the new owner after foreclosure would be required to pay those off.
When your first mortgage is foreclosed, then mechanics liens, any junior mortgage liens, including a second mortgage lien, are wiped out. Whether the mortgage insurance company has any claim against the borrower for unpaid balances is a separate matter, but the lien itself is gone. There have been many stories about junior lienholders issuing a charge-off against the credit report of the borrower for the unpaid amount, but this is the first time I have heard of someone trying to collect on that charge-off.
It sounds like you need to consult an attorney who specializes in that area to advise you. After all is said and done, you may be forced to file bankruptcy to clear off a debt that persists after foreclosure of the property.
as is mentioned here.