compgen's glob matching does not respect dotglob being turned on or off unless some other globbing takes place between the setting being changed and compgen being called:
$ cd "$(mktemp -d)" $ > .x $ bash -c 'shopt -s dotglob; compgen -G \*' $ bash -c 'shopt -s dotglob; : *; compgen -G \*' .x