Legalities aside, two facts allowed this transaction to work for Amherst:
1. The amount of CDS on the bonds in question was significantly larger ($130 MM) than the bonds outstanding ($29 MM). This is critical because if the amounts were equal, it would cost Amherst more to "fix" the bonds than the amount of premium they collected.
2. Amherst had to "manipulate" the value of the bonds in order for the trade to work. That is they used a portion of the premium from the CDS they sold to pay the servicer who in turn paid par on the outstanding amount. A servicer will sometimes pay the last small portion of a bond off if they collected tons of fees on the rest of the loans securitizing the bond. Given that a huge portion of these loans defaulted, it's unlikely the servicer had collected enough fees to do so. The only way the servicer could cover the remainder of the bond (the last $29 MM of the original $335 MM) is if Amherst paid them.
So the bet the banks made was correct, the $29 MM of bonds outstanding in fact became worthless. Amherst simply injected cash into it to make it worth par.
This is not a new issue. Derivatives are generally based on some index, and in this case the index was the value of these bonds. The risk is always that someone will manipulate the index. There are hundreds of stories of index manipulation in order to profit (or prevent losses on a derivatives trade), ranging from bidding up an emerging market bond to prevent a knock out trigger to manipulating the closing price of natural gas futures that changed the payout of a natural gas swap. In some cases index manipulation is perfectly legal - for example if one has enough capital to trade enough of the "underlying" to move the index. Those who enter into a derivative contract must be aware of such risks. In other cases it may be illegal - we'll see what happens in the case of Amherst (this case is equivalent to selling protection on a company's debt, and then funneling the CDS proceeds to the company to keep it from failing on it's debt.)
The fact that the size of the protection exceeded the size of the bonds is not a new issue in derivatives as well. The index can be the temperature or precipitation in a certain location for a weather derivative. How do you scale that contract relative to the underlying index?
But people are angry that the banks made that bet at all. How dare banks make bets! This is not a casino! Well friends, the biggest bet the banks had made is lending money to all of us on our mortgages. Over the years they made sick amounts of money lending to us and we kept on borrowing. But in the end that bet went awfully wrong. To try to reduce some of the pain from that massive bet gone bad, some made a small bet in the opposite direction on what remained of the mortgages in the Amherst case. In fact banks bought protection on billions of dollars worth of mortgages to try to limit their exposure - Amherst was just a small part.