The infantry square was a formation used against cavalry. Warfare was a rock paper scissors game. Square trumped cavalry, cavalry trumped infantry in line, artillery or infantry in line trumped infantry square.
It all worked fine until the American Civil war and the rifled musket came along. Repeating rifles, machine guns and shrapnel firing artillery made fighting in the open suicide in WW1.