As a follow-up, weren't they using squares since the time of Charles Martel? Probably earlier. This doesn't seem like a Napoleonic specific trait.
As another (sorta related?) follow-up: It seems as if the sqare died out after Napoleon, am I missing some conflict where it was still in use? If not, what changed to enable infantry to fight off cavalry without it?
Square permits mass firing towards the charge while keeping the horses from just running past. They'll stop at the outer bayonet line and try backing away, screwing up the rest of the cavalry charge. If you were in a circle, they could more easily veer around you if you are able to hold your formation.
Squares were most useful by infantry supported by a few cannons, and mostly against unsupported cavalry charges, as being in a square makes you more vulnerable to cannon.
The increasing range of firearms (to include the transition to rifles) made unsupported (and non-surprise) cavalry charges a waste of men and horses after the Napoleonic Era, but before the next set of major western wars (Crimean and American Civil).