If the purchaser from the foreclosure or bank sale has no relationship to you, and you enter into an "arm's length" negotiation to purchase from that person, then you have not violated any law.
If you have a preexisting relationship, and the transaction is not "arm's length," and especially if you worked out this chain of events in advance, and did not disclose your plan to the bank, then by your inducing the bank to sell to a third party for the purposes of reducing your loan obligation, so that you could repurchase the property at a lower cost, you and the previous purchaser may have committed federal bank fraud (18 U.S.C. 1344). This is a big-time white-collar felony/crime (up to 30 years imprisonment and a $1,000,000 fine).
So, the answer here is that if all this just happens by chance, then you have no liability -- but if it's contrived in advance, then don't even think about it.
Hope this helps.
NOTICE: My goal here is to educate others about the law. I am always available to answer your follow-up questions after you click Accept – however, if you do not click Accept, the website gets paid, and I receive nothing. This is true, even if you are on a subscription plan. So please click Accept, so that I will be able to continue to provide this service for others in the future.
And, if you need to contact me again, please put my user id on the title line of your question (“To Socrateaser”), and the system will send me an alert. Thanks!