You can think of the sheriff's sale as transfering ownership interest from the owner to the foreclosing entity, and your closing as transfering ownership from the foreclosing entity to you. So technically, the dues being paid or not, or stolen or not, before you closed shouldn't be your problem. That doesn't mean some party here won't try to make it your problem.
I would suggest getting legal help, but I would also ask if it's worth it. Mortgage lenders (like yours) don't like to let the borrower (you) assume any previous or outstanding leins against the property and the title company does their best to see that there are no undisclosed leins, but it happens on occasion. You could check with the title company, and see if you have title insurance, and if it would help in this case. You may have tried this already, but if you haven't yet you may look in to negotiating a lower payoff with the HOA. They may settle for less knowing that it will be a hassle getting the money from you (since this really isn't your fault), and even harder getting it from another party.
Finally, you have to ask yourself if all this is worth it. $5k is not an insignificant amount of money for any of us, but keep in mind legal help isn't free, and all of this will involve time and hassle. Maybe you just pay it even though you know you're right and they're wrong, and you can get on with enjoying your new home without worrying about the threat of foreclosure.... more