Spears, real spears, are a Eurasian innovation. Other continents independently developed variations, like javelins or short spears, but Eurasia had horses. When humans developed riding those horses, or camels, the natural evolution was in long spears as a counter.
And one of the highest developments of spear tactics is the Greek phalanx. The image speaks for itself. The upper raised sarissas (long Greek spears, practically pikes) are pointing high to help deflect incoming arrows. The high organization, training, and discipline to hold formation in the face of charging cavalry, was the start of organized militaries.
Horse-mounted cavalry has always had a big advantage over men on foot, so this is its response. Of course, the obvious defense is that imposing wall of pikes, but more important is that horses will rarely ever charge headlong into fatal peril. This causes the horse to rear back, buck or turn, at the very least losing the momentum of the charge, if not throwing the rider.
It’s also effective against everything, from up front. Warfare between the different Greek states tended to result in long lines of Phalanxes facing off and seeing who gave up first. It has a clear weakness from the flanks and the rear, so those same Greek armies would each keep their lines long, each trying to outflank the other.
Alexander the Great took the phalanx and combined it with effective use of cavalry. He would use the line to screen his movements behind the line, allowing his cavalry to move and outflank. After his death, Greek tactics reverted to the over-use of the phalanx in most cases.
Still, its formation continued in popularity into the middle ages, where pike formations were formed similarly.
The last moment of glory for Sparta, for example, was in forming a phalanx to turn a charge of Visigoth raiders in the post-Roman period.
