Edit:
I would point that it's really irrelevant that BM soldiers didn't have bayonetted muskets. The lancing technology was pretty well developed by that point. Swords were a rich soldier's equipment; a lance (when not a pointy stick) was still the weapon of choice for peasant armies and simple militias.
Using only spears, a cavalry square is almost worthless. What i think isn't being understood here is that the point of the square is so that the infantry can fire in all directions without being outflanked. A cavalry charge's worst enemy is a well timed volley. The musket is key. It keeps the cavalry from reaching the square. As soon as a horse comes close to the square, everyone's !@#$ed.
Think about it like this. You are an infantryman with a spear and you are a part of a cavalry square that is currently being attacked by a cavalry group. Let's assume that the numbers are not equal, 100 infantry v 50 cavalry and let's also assume that since you only have spears, the technology of the age implies that cavalry is in fact armoured (lets also assume that the cavalry is not equipped with lances which, while common during the age, would outrange the spears and !@#$ up the square, and this scenario) .
So you and your comrades are all set up with spears prickling outward and whatnot, 25 men per side lets assume. So the 50 man cavalry group is coming at you, they're just trotting now since they're 100 yards away but as they get closer, damn close, they break into a gallop and now you have a colomn of fifty galloping horses charging down on your side of the square. Lets assume you, nor your fellow infantrymen break down in fear, you just hold on to your 7 foot spear and brace.
So as the horses approach, some of the ones in the front are like "whoa this is a bad idea" and they try and stall or veer off. But! because of their tight formation, battle training, heavy armour etc, they stay on path and CRASH hit the square like a runaway train. Sure the first rank of the cavalry is filleted on a spear but those same horses have fallen kicking and dying upon the infantrymen which completely ruins the integrity of the square.
In the chaos all the rest of the infantrymen on other faces of the square are likewise slaughtered.
So, in conclusion, in the medieval ages squares were not used to protect against cavalry. The cavalry square came into popular usage during the napoleonic period and was made effective by the advent of muskets.
Medieval tactics used against cavalry were mostly, don't fight on open terrain. Simple as that. Find a hill, find a marsh, find a forest. BAM, no more cavalry problem.
If you have to face them in the field, a phalanx with polearms was used. But generally this only worked with large numbers and support divisions to ensure the cavalry didnt flank.
In BM cavalry is pretty easy to fool. Set up a meatshield unit in front, and then have a second wave hit as soon as the cavalry loses their charge bonus against the first wave meatshield. Or peace out and fight them in a townsland with a wall in front of you. Horses only have clumsy hooves that can't climb delicate siege ladders.
This is battlemaster. the tactics are not that complex to begin with. if you want a straight forward game where everything gets beaten by something, play rock paper scissors.
Also, if cavalry got !@#$ed up everytime some commander set his unit to box, what would be the point in investing hundreds into a proper cavalry troupe.. Sorry this is turning into a rant.