The ability to fight infantry from horseback or any animal for that matter was a great advantage for the riding men, as the higher elevation gave the rider more angles of attack, while also making it harder for soldiers down there more difficult to defend from the strange, downward thrusts.
This was coupled with the fact that the riders were able to put more force into their attack from the higher ground, thus able to tire the defending soldier more quickly and then break through his defense to deal greater damage.
And this was not even mentioning the role of the horse or camel, who was many times able to aid its rider by attacking the enemy with its kicks, and sometimes even biting down on them, tearing chunks of flesh in the process.
Thus, when an equally numbered cavalry fought infantry, it was usually the former who came out at the top, for they were able to deal much more damage.