PMI, or the equivalent, is supposed to only pay the bank the difference between what the house sells for and the balance owed (plus accumulated late fees, back interest, foreclosure fees, etc.).
In the event the bank actually collects more than it's legally entitled to keep the excess is supposed to be given to the foreclosed person.