BUG: fix sorting with observed=True in groupby
- [x] closes #25167
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Fix bug in #25167.