He basically believes his purpose is to build what the US DoD has been asking for for decades.. a space-based defense system, powered by AI to project force across the planet ("for our own good"). People who know him closely are aware. For example Grimes leaked a lot of this.
To be fair, Elon believe he's doing what he's supposed to / what is "right". It's just not the same as what he says to get people to work for him or be his fans. Talented people often won't work on military technology if they know that's what it's for, so he bends the truth.