Also note that standing shoulder to shoulder was an ancient method of warfare that went back to before gunpowder to the classical greeks and earlier.
If you mass your troops they can concentrate their weapons (swords, arrows, spears, muskets) on one section of the enemy. And if the enemy isn’t concentrated, that means that 100 of your guys can attack 50 enemies at once. It’s easy to see the power of fighting at a 2-1 advantage. So if your troops are exactly equal in ability, you’ll have killed 50 of his guys while he killed only 25 of yours. And if you’re equal in numbers, now you just point your 75 guys at the 50 remaining enemy guys, and wipe them out.
In modern warfare, a group of guys who just stand in the battlefield without cover would be massacred. But muskets were so inaccurate and slow to reload that it was a common tactic to just stand there and ignore enemy fire. And of course, you pretty much have to stand to reload a musket. And when your troops are standing in a line, they won’t shoot each other by accident. And when they’re standing in a line their officers can see what they’re doing, and prevent individual soldiers from running away, or not firing their weapon. And it feels a lot safer if your buddies are all around you to back you up, so you’re less likely to run away. And if you ran away all your buddies would see you were a coward, and so you’d be ashamed to run away.
And you didn’t have people loading and firing their muskets as fast as possible because you’d always have to worry about a cavalry charge, or an infantry charge. If you fire your muskets then your troops are relatively defenseless until they can reload. So commanders would order their troops to hold their fire until the exact right moment. And since musket fire was incredibly inaccurate, firing at long range was a waste of time. You’d wait to fire until you were right next to the enemy, and then volley fire and reload and volley fire again as fast as possible, waiting to receive an enemy charge or for the order to charge the enemy when it looked like they were wavering.
And this is where the archaic soldierly ideal of ice-cold obedience in the face of death comes from. If your side side starts to run away, they can be hacked down with impunity by enemy cavalry. And so even when you’re taking heavy casualties it’s better to stand there and keep firing rather than run, because routing means you’re even worse off.
So marching shoulder to shoulder into the face of enemy fire, and waiting to fire on command was a proven war-winning tactic for centuries, until rifles made it foolish and then machine guns made it literally suicidal.