You can only forclose on a home on which you hold a lien. One of the big problems associated with this mess is that banks couldn't figure out which bondholders owned which mortgages. The junk mortgage companies (one of which BOA acquired) were as good with record keeping as they were with underwriting. (That is, really bad)
Many homeowners skated through this mess with a free house because the banks could not actually prove that they have a valid lien on the home. The downside for these folks is that they are trapped in the home, as the title isn't clean.
It's also worth noting that while they couldn't track down the lien, they probably didn't screw up and foreclose on anyone who didn't deserve to be foreclosed upon.
At least, that's what the Fed's audit (of a sample of foreclosures, not all foreclosures in the US, obviously) said.
That was based on a review of only 500 selected mortgages. At the same time, the Defense Department is pursuing JP Morgan for incorrect foreclosures on military personnel overseas. There have been lots of cases (anecdotal) of foreclosures on mortgages that have already been paid off or houses that weren't even mortgaged. It's been a massive, massive screwup.
I can't speak to the numbers, but I've read about foreclosures thrown out of court by judges in the WSJ and Economist, so it has happened -- at least in the early days of the mess.
As you noted above, a foreclosure might fail for more reasons than simply foreclosing on someone who doesn't deserve it. Every case I've read about has simply involved the bank screwing up paperwork and a real estate speculator being permitted to keep the house even though they failed to make payments.
Many homeowners skated through this mess with a free house because the banks could not actually prove that they have a valid lien on the home. The downside for these folks is that they are trapped in the home, as the title isn't clean.