Twitter could have let him out of the deal but forced it. This is all on the (now former) board of directors who probably received a nice payout for a new mansion.
This was not an option with a publicly owned company. For the board members to walk away from this offer would have breached their fiduciary duty. They certainly benefitted as did everyone else with stock.
That fee was for external factors causing the deal to fail. Musk was already committed. His attempt to walk away was construed as breach of contract, and he would be liable for much more than the fee if that had happened.