A few counter arguments to GrayMouser's post:
An important detail about Battle of Garcia Hernandez is that the horse crashing into the formation was exceptional and unexpected. Squares were rarely disrupted with just cavalry without horse artillery or infantry support. Also before giving muskets too much credit in the Napoleonic era square it should be remembered that all other infantry formations were considered extremely vulnerable to cavalry even though they would have much more firepower to use against the attacker. The musket fire alone is not enough to repel competent cavalry. It's highly unlikely that cavalry would purposefully remain at full speed and direct course if it was just a couple meters away from an infantry formation that shows no signs of weakness, while a broken and fleeing formation would have plenty of space for the cavalry to squeeze in and start the slaughter.
Did high medieval shock cavalry rely on the infantry being bad? I think that was indeed largely the case (much like mounted police rely on the mobs being routed rather than crushed by the horses): Without getting more deeply into the high medieval period we can simply looks at the changes that started during 14th and 15th centuries (with Scots and Swizz showing that knights are in fact not unbeatable by infantry) and how that developed into shock cavalry falling out of favor during early pike-and-shot era when pikes were still the dominant weapon system of the mix.
Regarding the physics of horses ramming into infantry, I think the momentum is the biggest problem. Even if humans would be on the losing side of the collision, the horse would hardly be able to keep balance when slamming its limbs into the mass of people. It could be roughly analogous to covering the floor of a room with chairs and waste baskets, then running through the room at high speed while someone is riding you piggy bag. You would certainly have the advantage on momentum compared to the furniture but do you really think you would still be on your feet on the other side of the room? (It's admittedly a VERY rough analogy

)
I have been known to occasionally quote events of Carrhae. They way I have understood it the Cataphracts were literally riding between the roman formations and shoving their lances into the testudos with any attempts to sally by the frustrated Romans being met with arrows from the horse archers. The issue there wasn't as much the tight formation being inefficient against the heavy cavalry as it was Romans being completely toothless in the testudo that was not designed for melee combat.
About the medium infantry: The entire "unit type" is (wargaming?) neologism with contemporary sources seeing no need to make such distinction between different kinds of heavy (aka. melee) infantry. The medium infantry having no cohesion penalty in the rough doesn't necessarily mean that they are not disrupted by the terrain at all but rather that they are relatively less effected than heavy infantry and cavalry. They still might have a fairly cohesive formation in the open even if it's not as well drilled and maintained as that of the heavy infantry. In any case, historical battles were rarely resolved in minutes with a rock-paper-scissors like absoluteness so I'm personally quite satisfied with the medium infantry simply being worse than heavy infantry against ancient cavalry.