I am not a doctor, but there are plenty of people with mobility issues who are fully mentally competent. Lots of people with disabilities drive adapted vehicles. Having had a good go at ageism, we're now onto ableism!
The only person in this position I've closely observed is my Dad. He was becoming frail in body but had all his faculties to the very end. However, I don't think he was strong enough to be driving, not because he struggled with the short, simple, very familiar local trips which were all he did at the end, but because in an emergency I wasn't confident he would have been able to react quickly and use his strength to control the car. It wasn't put to the test.