Tesla and SpaceX are currently in very, very different markets. Tesla is selling luxury consumer products, and trying to get the economies of scale + technical innovation to start selling non-luxury consumer products, where the real market is. They are also competing against an entrenched, widely-deployed technology that has been in widespread use for longer than 99.9% of the human race has been alive. They need their product to become more than a niche, and they need to have viable competition if for no other reason than for the legitimacy that competition brings.
SpaceX sells cheap, high-tech rocket launches, where cheap means something like what a "cheap" computer in the 50s would mean: governments and really big organizations can afford to buy them, and nobody else is even going to consider it. In a way, they're the opposite of Tesla: rather than being a luxury brand trying to get cheaper, they're aiming to be the cheap alternative to the existing competition.
Unlike Tesla, SpaceX is not publicly traded and does not file for patents. Patents provide no meaningful protection against the Chinese or Russian governments, which are the organizations SpaceX is most interested in competing with. SpaceX patenting their stuff would allow those entities to undercut SpaceX for the small number of customers that even exist in such a space, because they could use the disclosed technology without needing to recoup R&D investments or pay California salaries and regulatory costs.
The problem is that SpaceX is the only organization in the world currently demonstrating great success in disrupting the entrenched space launch market, and they need to (and do) re-invest their profits from those launches into producing still-better (cheaper) launchers if the want to achieve their stated goals of making space access cheap enough that actual human beings can afford it. They can't afford to be undercut, because there just aren't enough customers right now for them to afford to do other than fight for every purchase they can get. Tesla can totally afford to be undercut; it will help grow their market (electric car owners) and meanwhile there will always be people who will buy their cars just because the market is big enough.