Wow that sucks! Why would they even put the house on the market in that case? Some people are just jerks and like to screw with peoples' emotions.
This has never happened to us, that I am aware of anyways. I believe once a house goes into foreclosure, all offers are voided and you have to re-submit an offer once the bank makes the house available for sale again but as an REO. Good luck!