Many lenders had their portfolios of mortgages insured against loss due to a borrower's default, especially those loans that were originally made to borrowers with less than 20% down payments.
For this reason, each of these foreclosed loans becomes an open claim with a mortgage insurance carrier. The claim is traditionally settled when a foreclosed property is eventually sold to a new purchaser.
However, the mortgage insurance carrier has the right to take title to the house and pay the lender directly for the loss if they feel, based on their data and projections, that they have a better opportunity to reduce their own losses by taking title and reselling the property themselves.
It doesn't happen very often, but it is part of the process. MI carrier approval of a sale price typically only takes a day or two.