He purchased the company because his lawyers finally convinced him he was going to be forced to and that it was a poor choice to continue damaging the asset he was going to be owning.
That's your belief. It is quite likely that the court actions were mean to pressure twitter. That isn't an uncommon tactic. The two facts we know are that Musk stated he would purchase twitter to make changes, and he has started to make changes after the purchase.