BUG: Groupby-Apply with modifying dataframe and sorting overwrites group values 
xref #36602 

- [x] closes #36602
- [x] Ensure all linting tests pass, see [here](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit) for how to run them

Great! Thanks @kasmith11 