The ESM is probably illegal. Its existence violates the spirit and the letter of EU law, but this does not matter.
If the court ruled that the ESM was illegal, nothing would stand between those dodgy periphery bonds and speculators. A spectacular collapse in the sovereign bond markets would precipitate a panic throughout all of the financial markets.
The court does not want this responsibility, so it will rule that the ESM is legal. The court will reason that the ESM is not bailing out countries, but rather stabilizing the euro, which is allowed under treaty.
There is plenty to worry about in the ESM. Money has been pledged but not paid, periphery countries that may require ESM funds are expected to contribute over 30% to it, and the fund will exhaust all of its funds by just bailing out Spain.
You can rest assured that it is legal, because the court says so.