Most things I have read about horse archers portray their ability to avoid hand to hand fighting through mobility while hitting the enemy with ranged fire, whether it was against enemy infantry or enemy cavalry.
Is the above true? Were horse archers consistently able to avoid hand to hand fights or were they caught more often than portrayed by enemy cavalry or infantry?
If "1" is true, why did the use of horse archers decline? I understand that greater infantry firepower could hurt horse archers. But against enemy cavalry, if "1" was true, horse archery would be superior to wheellock pistols and muzzle loading carbines used by 17-18th century cavalry (which from what I understand were considered difficult to use from horseback) and also superior to early 19th century cavalry that seemed to only use a handful of ranged weapons.
Horse-archers would be very difficult to force into hand-to-hand fighting if they were prepared to retreat. They can be (and sometimes were) trapped and forced into hand-to-hand combat, with either terrain or enemy forces preventing their retreat. There have also been many occasions when horse-archer forces stayed to fight hand-to-hand rather than retreating because retreating, while saving their lives, would have led to the capture of their camp/supplies/families, etc.
Forcing horse archers to retreat from the battlefield can be, as far as the battle in progress is concerned, as effective as destroying them. If they are part of a mixed army (e.g., infantry, cavalry, and artillery) and retreat from the battlefield, the battle can be lost despite the survival of the horse-archers.
Thus, the most effective-in-battle horse-archers are those ready, willing, and able to engage in hand-to-hand fighting. While heavily armoured horse-archers might not be as mobile as light horse-archers, they can be much more effective in battle. Alternately, lighter horse-archers can operate together with armoured cavalry whose task is, in part, to protect the horse-archers.
Being able to engage enemy forces at a distance doesn't depend on archery, but on having missile weapons of sufficient range and effectiveness. Bows are one options among many. Javelins are a short-range option, and crossbows and firearms are other options. Bows will out-range javelins, and offer a higher rate of fire than crossbows and muzzle-loading firearms. Firearms (and possibly javelins) will offer better anti-armour performance. Until repeating firearms, or at least breech-loading cartridge rifles, the higher rate of fire can make mounted archery an attractive choice.
Note that it is possible to combine mounted archery with firearms. A musket or pistol can offer excellent anti-armour performance, and a bow can also be carried for use when a higher rate of fire is needed.
However, unlike the vegetable lamb of Tartary, the horse-archers of Tartary (and elsewhere) do not grow on trees. If a sufficiently large part of the population is herders who learn mounted archery in their youth, there will be a sufficiently large pool of recruits, and a sufficiently large force of horse-archers can be fielded in battle. If such a pool of recruits is not available, then suitable soldiers must be equipped and trained. Training horse-archers takes time - a force cannot be quickly raised and trained unless skilled recruits are available. While provision of warhorses will be a potential problem for all types of cavalry forces, horse-archers must also be equipped with suitable bows, if they do not provide their own. The composite bows most often used by horse-archers were expensive - typically more expensive than guns (at least from the 17th century onwards). Together, the demands for training and the expense of bows make bows less attractive in the early modern era when armies were typically growing in size.
Some armies maintained large forces of horse-archers well into the 19th century. Notably, the Chinese did so as part of armies where the musket was the main infantry weapon, and artillery was plentiful. But usually firearms were the preferred cavalry weapon.
also superior to early 19th century cavalry that seemed to only use a handful of ranged weapons.
Early 19th century European cavalry were typically equipped with firearms: pistol(s), carbine, rifle, or musketoon.
Finally, this old discussion on the effectiveness of horse-archers is relevant:
https://www.reddit.com/r/AskHistorians/comments/tq8ka/how_effective_was_the_horse_archer_back_in/
In summary, they aren't an invincible super-weapon.