Government infusions at key moments helped Tesla and SpaceX flourish, boosting Musk’s wealth.