Yes they do, it's called specific performance. It's not the usual remedy for breach of contract, but in certain cases the court will grant it. I believe M&A agreements are one category of cases where US courts are inclined to grant specific performance, but I'm no expert.
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.
Well the court could obligate Musk to pay damages. One (simplistic) possibility might be to take the value Musk agreed to pay minus the current value of Twitter and force Musk to pay that. Then in theory Twitter would have received same value in the end.
That last statement does not follow everything else before. Courts have no power to do that.