It’s a terrible idea because it’s a nasty way to treat people at the acquired company and probably ineffective at getting any useful information, but Elon Musk has shown that he doesn’t have many scruples about that sort of thing.
But SpaceX, Tesla, and Twitter don't really have common ownership in the normal sense. They're not owned by the same holding or parent company, they're not owned by the same single person, one is public and two are private, etc.
If Tesla engineers are spending time on something not beneficial to Tesla but instead to Musk personally or to X Holdings, that's absolutely something Tesla shareholders could sue for.
In this case Musk could easily say he had spare capacity, and if there’s crossbilling (which can happen retroactively if there was an objection) there’s really nothing to sue over. If he can get tesla engineers to try to build a cave rescue submarine to buff his public persona he can get them to do this.
This is also why Musk can get away with it - he's got fanboys, albeit of slightly different types, dominating the shareholders in both cases. (In the case of Twitter he may even be personally the majority shareholder with no obligations beyond cash now, but who knows...)
We don't have really any visibility into what short- and long-term obligations Musk owes the various financing parties.
Edit: https://www.reuters.com/markets/deals/saudis-kingdom-holding... says Saud is keeping their ownership stake post-merger (they just love free speech!), so I do not think Musk is a 100% shareholder.
If Twitter is paying above fair market rate, that's collusion to benefit Tesla at the expense of Twitter.
If Twitter is paying exactly fair market rate, why does it need to be Tesla employees? That starts to look like self-dealing to make Musk's live easier.
You can't really win in this situation, which is why any sane executive avoids such a conflict of interest in the first place.
(I'm not claiming there will be any repercussions mind you - if Musk got away with SolarCity he'll surely get away with this.)