As crazy as the Iranian regime can sound through its rhetoric, when it comes to protecting its interests, it‘s essentially rational and careful. Iran knows that it can’t afford a war against the United States. It also knows that further deterioration could mean more sanctions and further isolation, both of which would hurt the regime’s ability to sustain itself at home. This is more important to Khamenei's interests right now than the elimination of the Saudi Ambassador in Washington.
The fact is that looking at Khamenei's background, such a reckless initiative as the one he is accused of is almost too radical, the costs too high for his regime. This is why it seems at least plausible that elements within the Iranian regime could have orchestrated this to hurt him, with the goal of eventually pushing him out of power.
The Iranian regime is already fractured, and the business interests of many officials are being undermined by Khamenei's nuclear policies. Meanwhile, the children of former officials such as Intelligence Minister Ali Younesi, are reportedly in jail because of their opposition to the regime. Anyone who wants to hurt Khamenei from within would have plenty of reason to undertake such an initiative, especially as it would ultimately tar the supreme leader.
The Iranian government has been a sponsor of terrorism for many years. But this claim is truly extraordinary. If true, Khamenei has either been extremely reckless, or is being set up by opposing elements within his regime. Time, and the evidence presented in court, will help us get close to the answer.