If a home is foreclosed on and the bank re-sells the...

If a home is foreclosed on in CA ?and the bank re-sells the property, what happens to any equity remaining after all debts have been satisfied? Does the bank keep the profit, or does the previous owner (who was foreclosed on) get the equity?

The trustee is required to pay it out to junior debtors in order of priority, with any funds remaining to be returned to the owner. The bank only gets to keep what they are owed.
Note that this does NOT mean “all debts are satisfied” first. If a second mortgage forecloses, and there are excess funds, the first mortgage is not entitled to any of it. Other senior debt, like property taxes, also remain outstanding on the property and therefore are not typically in line to receive those funds.