Partly that's due to clustering: They produce hundreds of Merlins per year vs their competitors which only produce like a dozen or so (often less) engines per year, so just from the learning curve they can save a lot of money.
And unlike essentially every other rocket in the industry, the two stages are largely similar, using the same pressurization scheme, same propellants, same diameter tooling, just differing by the length and number of engines (the Merlin Vacuum engine is significantly different than the Merlin 1D sea level engine, but same underlying cycle type and same heritage), so it's almost like they only need to maintain half the production line as their competitors and get the economies of scale of producing more of the same thing. Also, they're reusing the vast majority of the hardware on roughly half their flights, now, which is, unhyperbolically, a game-changing development in commercial space launch.
SpaceX has a LOT going for them right now. Falcon 9 is a very inexpensive launcher given its performance.
The thing about rockets is that there's a huge advantage in having a higher launch rate. If you're not launching a lot, you're still paying most of your labor and facilities cost just to sit idle. And SpaceX, just producing a single rocket family that is launching more than anyone else in the world (and reusably), is at an enormous advantage there.
The limited information we have is that SpaceX is significantly profitable (their fairing recovery, Raptor, BFR, and potentially even parts of the satellite constellation efforts are funded out of their profits). They have one production line and are launching 18 times per year. Their nearest competitor is ULA, with 3 product lines (Delta IV Heavy, Delta II, and Atlas V) and with half as many annual launches and with no capability to reuse. That implies SpaceX's margin can be far greater than their competitors, the opposite of your guess.
In rocket launch, your profitability is determined primarily by your launch rate and your number of product lines as there are a lot of fixed costs for maintaining launch pads and manufacturing lines. SpaceX is doing extremely well on both fronts.
It's understandable if you haven't been following this very closely, as the situation has flipped dramatically in just about 2 or 3 years, even in spite of the failures during that time.
To give an example of Tesla:
Imagine Tesla was outproducing GM and Toyota combined, globally, and had also demonstrated level 5 self-driving Model 3s and Semis for the last couple years while readying to flip the switch on 300GW worth of solar to power their global supercharger network (powering tens of millions of cars) and power several medium-sized countries. That might be comparable to the situation SpaceX finds themselves in right now.