This phrase is connected to the idea that the moon is an unattainable target.
Shoot for the moon means to go for something that is probably impossible to reach.
There is also a lovely phrase by Norman Vincent Peale (Author of the best selling book 'The Power of Positive Thinking') who wrote: “Shoot for the moon. Even if you miss, you’ll land among the stars.” In other words: go for the best, and if you don’t reach it, you’ll still have achieved something.