The tl;dr here is simple: Mozilla made a hedge that Yahoo! would sell themselves to someone terrible during the period of their contract, Yahoo! did, and Mozilla collected on the proceeds to the tune of $350 million-ish USD.
It was a gamble Yahoo! was desperate to take, so they did, and it didn't pay off in the long run (especially since for a large number of users it simply meant a one-time nuisance of switching the search provider back to a real search engine).
But Mozilla made out like bandits on the deal due to their executives smartly calling the future of Yahoo!. Good on them.
News from 2016, but given that the yahoo contract was supposed to extend until 2019, yet Mozilla is now switching its default provider to Google, I found this article highly relevant.
> According to the change-of-control term, 9.1 in the agreement, Mozilla has the right to leave the partnership if — under its sole discretion and in a certain time period — it did not deem the new partner acceptable. And if it did that, even if it struck another search deal, Yahoo is still obligated to pay out annual revenue guarantees of $375 million.
How desperate must Yahoo have been to agree to these terms? Did Mayer really not know they were going to sell? Because even if they thought Mozilla would like the new owner this contract still incentivizes them to walk and collect two cheques.
Despite Yahoo being a terrible company, it's someone else's money! Do the right thing Mozilla - don't steal, even if your contact allows you to