Not really strange... if the goal is to go to mars, you probably need robots, those need intelligence -> ai. It fits pretty well, especially because you want to own all the core technologies as a company.
He sold his failing but hype business to his soon-to-IPO successful but kinda boring business.
It's a way of laundering the debt and dumping into investors as he pitted different indexes against each other to force his way into one of them, and have people's 401k buy into them. Its a ton of money.
I wouldn't be surprised if Tesla is bought into spaceX in the future.