For Shimano it’s simple:
All 7,8 and 9 speed MTB and 7,8,9 and 10 speed road rear mechs work with all 7-9 speed MTB and 7-10 speed road shifters.
10 speed MTB mechs only work with 10 speed MTB shifters and 10 speed MTB shifters only work with 10 speed MTB mechs.
It’s not the distance the mech has to travel that’s the problem, it’s the amount of cable the shifter pulls to achieve the travel.
For example, a 9 speed shifter may pull 5mm of cable per shift (it doesn’t, but go with me), so when the 9 speed mech feels 5mm of cable pull, it moves between 2 adjacent sprockets. If a 10 speed shifter pulls 10mm of cable per shift then a 9 speed mech will move across twice as far, missing out one of the sprockets. So a 10 speed shifter will have a shorter lever on it so it moves a shorter distance.
Hopefully that’s clear!