So recently my uncle gave me a Deore M5100 11 speed RD, but my current setup uses an Alivio shifter with a LTWOO A5 elite RD and an 11-46T cassette. While yes the LTWOO RD is designed to handle a 46T 9 speed cassette, im wondering if a Deore M5100 can handle not only the 9 speed shifter, but also the 46T cassette. Based on my minimal research, an RD doesnt particularly know what "speed" it is, rather the shifter dictates how much it moves. Thats why im thinking that the M5100 is fine even if im using a 9 speed shifter and cassette. Of course, a longer chain would be needed in that case. I am aware that you should always match drivetrain components, but in a hypothetical scenario will it work? What do you guys think?
You're correct in your reasoning: the shifter defines in which speed the derailleur will be. The points that you miss are the notions of cable pull (the movement of the cable when you change a speed, in mm) and pull ratio: which is the ratio between the cable pull and the lateral movement of the derailleur (dimension-less number).
A 9-speed shifter has cable pull of 2.5mm and an 11-speed MTB derailleur has a pull ratio of 1.1, which means that the derailleur will move 2.75mm per level when you actuate your shifter. But the distance between the sprockets for a 9-speed cassette is 4.35mm, so your derailleur won't move enough to reach another sprocket.
For reference: 9-speed systems have cable pull of 2.5mm and pull ratios of 1.7. 11-speed systems have cable pulls of 3.6mm but pull ratios of 1.1.
There are adapters that allow to use derailleurs and shifters that don't match (like the Wofltooth Tanpan), but as far as I know, they are mostly used to allow using road shifters with MTB derailleurs (or the other way around).