There are actually two types of PMI out there. The first one is the most well-known and is also called lenders mortgage insurance. It is insurance to offset losses in the case where a mortgagor is not able to repay the loan and the lender is not able to recover its costs after foreclosure and sale of the mortgaged property. The second type is quite rare and is taken out by the borrower to protect their investment.
The first type is what you refer to in your question. I've supplied a wikipedia link to an article describing this type of insurance in more detail. And yes, banks do foreclose to take possession of the asset that was the collateral of the loan. The PMI is only there for their protection if there is a shortfall between final market value of the repossessed asset and the loan amount. Hope this helps to answer your question.
Jacobus "Jack" Vollenberg
RE Appraiser/RE Sales Associate
Vollenberg Appraisers/ERA Statewide Realty