I believe, in simplest terms, if you purchase a foreclosed home from the mortgage company you do not owe the balance on a mortgage. That is the point of foreclosure. The entity servicing the debt would like to recoup as much of that as possible and can only do so by selling the asset. Outstanding HOA dues, loans attached to the property, etc. I would image are a separate liability.
BTW - homes that are in foreclosure due to unpaid HOA fees rarely actually end up going through foreclosure.