Ability can mean capacity
"He has the capacity to do well in school."
However, capacity can also mean having authority.
"He made a decision in his capacity as mayor."
Capacity is also a legal term, meaning the ability to perform some legal act.
The term 'diminished capacity' is a legal term meaning a person could not be held legal responsible for their actions because of their confused mental state.