in most states, the HOA takes subject to the purchase money mortgage [and any refis of it] and the prior owner is out. Thus, the HOA now has to make the mortgage payments out of the rent it receives or out of the sale amount when the property is later sold.

BUT -- in most states, the prior homeowner is not off the hook. S/he/they are still liable for the full amount of the mortgage and the lender can still sue them, etc. It's just that they've been evicted and do not have the right to collect rent [the HOA does].

Btw, the HOA can still sue the prior owners for the back dues, etc. The foreclosure does not end their rights to collect from the prior owners.