When, and why, did cavalry become irrelevant in warfare?

by drabant
Juvenalis

To clarify, we should establish whether 'cavalry' should refer to 'hose-mounted fighters' or specifically fighters who fight 'in the saddle'. For example, fighters mounted on horseback feature throughout 20th century history, for example, in the case of the Rhodesian 'Grey's Scouts' who fought in the Rhodesian 'bush wars' of 1964-1979.

Unfortunately the phrasing of your question presupposes that "cavalry are irrelevant" when horse-mounted fighters are very much in vogue in modern history, for example in Afghanistan, where successful horseback attacks are reliably accounted for, and operations as 'cavalry', not merely 'mounted infantry' who dismount prior to giving battle:

Wolfowitz read excerpts from declassified field reports that describe some of the experiences of those special forces in battle.

"I am advising a man on how best to employ light infantry and horse cavalry in the attack against Taliban T-55 (tanks), mortars, artillery, personnel carriers and machine guns -- a tactic which I think became outdated with the invention of the Gatling gun,'' wrote one commando in an October 25 report, Wolfowitz said. "They have done this every day we have been on the ground.'' [...]

The dispatch relayed how Northern Alliance horsemen "bounded from spur to spur to attack Taliban strong points -- the last several kilometers under mortar, artillery fire. They have killed over 125 Taliban while losing only eight,'' the commando wrote.

Unfortunately, owing to the subreddit '20 year rule' I will have to shut my trap at this point, but this is a vital point pertaining to your question. The assumption that horses are unviable in combat is really unfounded; images of hapless, backward horsemen being cut to pieces with modern weaponry such as with the supposedly disastrous deployment of Polish cavalry against the Germans in 1939 has been rigorously refuted by researchers - it crops up in this subreddit occasionally.

To quote from /u/Brickie78 's great post in that thread,

Although trained as mobile anti-tank/dragoon units, Polish cavalry retained the sabre, just in case. On 1 September, the 18th Pomeranian Uhlans were covering a retreat when they spotted a unit of German infantry resting in a clearing. Colonel Mastalerz decided to take them by surprise and ordered a sabre charge of about 250 cavalry. The charge was successful and the German infantry - who can't have been expecting cavalry with sabres charging them - dispersed into the trees with heavy casualties.