Elon Musk’s company had appeared set for a big windfall—while he has railed against biased government spending.