I know that generally if you own a company you can just dissolve it, however can Twitter have certain rules set up in their selling contract or perhaps because it's such a large company, can they somehow stop Elon Musk from just dissolving the company if he felt like it?
Elon Musk doesn't own Twitter
He is part of a consortium of investors that own it. What he can and can't do with it will be constrained by any agreements that exist between those investors and, as CEO, a duty to all of the shareholders and to the company itself.
However, that jus begs the question: can the "owners" of a company dissolve it?
Or, more precisely, the directors acting for the shareholders can cease operating the company, collect all that it is owed, pay all that it owes and distribute wherever is left over to the shareholders. If there won't be anything left over, then the directors have a duty to point an administrator/liquidator to finalise the company.
One of these two things is, ultimately, what happens to every company sooner or later.