Originally the commands were one array indexable by the enumerators, but as its now several separate groups of variable size (at startup time). The macros are intended to map the old enumerator names to the new organisation, the group and the command within that group.
I don't remember that long ago, but since C enum values are not limited to the values of the enumerators I suspect testing for out of range values was just ensuring a known return for out of range inputs.