Your question is underpinned by a key misunderstanding of the course of an ancient or medieval battle: the slaughter occurs in the pursuit (or endgame if you will), not what might be termed the battle proper (or midgame).
Prior to the invention of artillery, and breech-loading and automatic rifles, very little death is dealt out during the main course of most battles. Battles were about slowly eroding the endurance and will of the opponent, so that they were the first to decide that the legs were too weak to power a blow, and the arms too tired to hold the shield up or parry. At that point the opponent has lost morale and breaks; and the pursuit begins. Over the course of a long or large battle, both sides typically would have opportunities to rout, and inflict significant casualties on, small portions of the other side during this jockeying for advantage.
Heavy cavalry was used to push an already tired opponent over the edge through the psychological effect achieved on the enemy. As the charge closes to within a hundred yards and the horses enter their gallop, the very ground quakes to such extent that the facing infantry are physically shaken, their knees forced to wobble by the very movement of the earth. Tired infantry, experiencing this for the first time, can be physically thrown to the ground like a landlubber in his first storm at sea. When the charge has been properly timed, the infantry breaks and the pursuit begins; first by the heavy cavalry to prevent a reforming of the infantry, then by the light cavalry to complete the slaughter.
If the charge has been ill-timed, the horses pull up about 20 yards from the infantry, and the combination of frame saddle and stirrups enable the riders to comfortably remain mounted. Lancers can now engage in a little square-breaking unless the infantry is either similarly equipped; or supported by either missile infantry or friendly cavalry who can readily target or counter charge the (now slow-moving) enemy cavalry;
During the European Medieval Period infantry was nearly always either a conscripted levy or mercenaries; only the latter would have the discipline, training, and experience to withstand the morale shock of a heavy cavalry charge. Consequently the end-game exploit of a heavy cavalry charge moves up in the order, and can be executed very early in an attempt to either immediately rout the opponent, or gain an advantageous position for one's own archers. It is this arrogance on the part of the French knights, understandable in other circumstances, that leads to the English victories at Crecy, Poitiers, and Agincourt due to premature charges.
With rare exceptions due to exceptional training, morale and equipment, only when cavalry is able to find the flank of its target, utilizing its speed and mobility, is a charge ever carried home against a formed opponent:
Contrary to the popular belief, the cavalry charge as well as the
defence mounted by the square of infantry were chess--like games of
cat and mouse. The Polish--Lithuanian Commonwealth's Hussars were
known to charge the same square many times before committing
themselves to penetrating and dispersing it. A beautiful example of a
success of such fast mobile, but cautious tactics is the
Commonwealth's victory during the battle of Klushino. It took the
Polish--Lithuanian Hussars 8 to 10 attempts to break through and route
the Russian and Swedish forces. [ibid]
Note the psychologically wearing effect on the infantry of not knowing when the charge will be carried home, but of having to be completely ready every time.
There are a number of successful square-breaking examples from the Napoleonic period, which can be classed into four categories:
- deceit - typically when Hussars can pretend to be a different nationality;
- accident - black powder smoke prevents the horse from seeing the square in time, who then pull up too late and fall into the square allowing successive riders in.
- mismatch - elite cavalry against untrained infantry, with the square routing just before impact.
- timing - square incompletely formed at impact, equivalent to cavalry finding an open flank.