It's common for companies who both patented technologies each other need to use to make an agreement where they exchange rights to use each others patents. It is strategic and keeps them both moving forward while still keeping the little guy down.
It is not the ideal way, but would you rather they made a gamble and failed against the legal framework (their opponent is not really Yahoo after all), or spend some upfront capital now to protect both their customers, employees, shareholders and even end-users.
If it helps, you can think of software patents like a tax on business, especially the larger you become. If you were Facebook, would you take the risk of not paying your taxes, particularly on your public share offering?
At least, protecting themselves now gives them the option to fight however they think is most effective. Without it, they are just legal easy prey.