Why wouldn't courts have the power to do that? If the court rules you have no grounds to terminate the contract then you will have to execute the contract as originally agreed upon.
How Musk gets the money in order to fulfill a contract he's entered into is immaterial unless he goes completely insolvent and still can't fulfill it, which will not be the case.
The banks also signed contracts stating they’d loan the money using Tesla shares and Twitter equity as collateral. They can’t get out of that contract just because musk wants them too.