Why did Shakespeare categorize man into seven ages in his poem The Seven Ages of Man Why not 5 or 10?

In the first place the idea of the seven ages of man was not found by Shakespeare. This idea had been around for a long time, and finds its origin in a Latin phrase. Shakespeare was only the man to voice the idea, and in that he succeeded very well.

The number seven is probably derived from the seven sins. The number seven can be found several times throughout the bible and can be seen as some sort of symbol.

If you would like to know more about the origin of this famous quote, I refer you to the Wikipedia page on the 'all the world's a stage'.