The law mostly. Otherwise ownership of companies would be mostly pointless, similar to that of gambling (in that your fate would be mostly random, more so then it currently is).
I agree with you that yahoo should have sold to microsoft, by the way. But the legal duty to maximize value bit is just not accurate.