No, that's not legal. Trying to back out of this deal because market fluctuations caused the company to be worth less than he wanted would be very, very much against his contract.
He can only back out is Twitter's securities filings are so wrong that profit projections are more than 40% off (MAE standard) or he was unable to secure financing. Spambots being a bit higher than projected is not enough to break the contract, especially given that Musk waived due diligence and that the Twitter filings have always said that the bot number is an estimate. Elon Musk's lawyers are probably more than a bit panicked right now.