SpaceX is located on a campus previously created for building aircraft, so it seems they are where they need to be.
https://en.wikipedia.org/wiki/SpaceX#FacilitiesAlso, that part of LA (hawthorne, el segundo), has a history of aviation and rocketry companies, so it has better facilities and a larger built-in talent pool too.
They do co-locate some operations (tesla designer lives in the SpaceX office, not the tesla office), but it makes sense for Tesla, as a consumer brand, to be located in the most densely concentrated location of multimillionaires and billionaires in the world.