I may have been unclear. He wouldn't have to buy Twitter if the government prevented it, but he would be required to pay $1b. Outside of those circumstances, he is contractually forced to buy Twitter.
The government issue and the money issue are basically the two scenarios in which Musk would be unable (not just unwilling) to complete the transaction. So that's where he has to pay the fee. Otherwise, he can't change his mind.