"If someone paid 500K of a 600K loan and then forecloses, what do they get back?"
You need to clarify your post.
If you are talking about buying a mortgage note at a discount and then foreclosing on the property it would work something like this.
800,000 mortgage and you buy cash from the bank at say 500,000.You approach the borrower to work out a new plan to get them on track.They don't want to comply so you foreclose.
You put bid at auction of 600,000.The price gets bid up to 660,000.
You buying the mortgage at a discount just made 160,000 in profit.Of course there are attorneys fees and time line to foreclose and a host of other things that affect this.
The bank has to want to sell the note at a discount to begin with while in pre-foreclosure.
no legal advice