There's a series of posts on WaitButWhy[0] about Elon Musk and his various companies and strategies. The level of Musk worship there generally rubs me the wrong way, but I think the conclusions are valid: the author also interviewed Musk one-on-one in 2015 and took a deep-dive into his businesses, so I would trust the author's conclusions. Essentially, Musk expects/worries that an extinction event (whether as a result of climate change, an asteroid impact, or whatever) will wipe out humanity on Earth, and believes that the best hope for our continued survival is to colonize other planets.
[0] https://waitbutwhy.com/2017/03/elon-musk-post-series.html