This might really be more of a physics question than a history one, but I hope you can help me out or at least point me in the right direction!
Most amateur historians are familiar with the concept that spearmen are effective at defending against cavalry charges. I've even read (in the Sharpe books, so not exactly scholarly but I have heard they're well-researched) that horses would generally refuse to charge spears (or in Sharpe's case, bayonets) suggesting that they worked as a deterrent to charging, rather than just a counter.
However, assuming that the cavalry did successfully urge their horses into charging prepared spears and the spearmen did their job of holding the line and killing the horses, surely this would represent a death sentence for the spearmen too? Googling some statistics, a horse can weigh between 380-1000kg and reach speeds of 88km/h. Could a line of prepared spears (or pikes or bayonets) really expect to stop that level of force from hitting and killing them, even if the horse and rider were also killed?
Let me guess, you just finished (or remembered) that bit near the end of Sharpe's Sword? Aside from the inclusion of Sharpe, that did happen, being the Battle of Garcia Hernandez.
This previous thread with discussions from u/Iphikrates, u/Iguana_on_a_stick (who also includes an account of a charge at Omdurman in 1898), and others, should provide a fair bit of thought into the matter of cavalry, though I grant that it doesn't directly address the matter of dead horses hitting infantry formations. u/ErzherzogKarl further down that thread also notes that there's some room to doubt the account of Garcia Hernandez.