To concentrate a wall of spears it requires that only so many men can be deployed in width, making the lines shorter than many equivalent formations.
Also it doesn't help the phalanx that the roman army started reforming around that period towards even more flexibility (what I like to call the "scipionic reforms"), meaning that the tactical usage differences between hastati, principes and triarii started to soften.
Another important factor is that we're talking about veteran legions, meaning more skilled and better equipped than your average roman force.
Bookmarks