Generally the HOA lien will be wiped out the foreclosure and the bank won't care about the HOA assessments due. The bank will have to pay the HOA fees after foreclosure if the bank buys the property at foreclosure, or else the purchaser of the property will have to do that. The purchase by the bank or another purchase won't be subject to the extinguished HOA lien, but again, new HOA fees will be due and payable.
As usual, this answer does not constitute official legal advice and does not create an attorney-client relationship between the poster and me.
If the mortgage lien is superior, which it probably is because most HOA declarations provide for a purchase loan's superiority, then the HOA lien will be wiped out by the foreclosure of the senior lien. If the HOA lien is superior, then you can foreclosure the property from the mortgage company. Unlikely that mortgage holder will deed the property for just the principal unless they do not believe they can sell for more.
You probably need to hire a real estate or creditor attorney to assist you.
If this response was helpful, please mark it as helpful or as a best answer. The response provided herein is for informational purposes only and is not intended as legal advice, nor does it establish or intend to establish an attorney-client relationship. You should always speak with a licensed attorney regarding your legal rights before taking or not taking any particular action.