BUG: Fix segfault in Categorical.set_categories
- [X] closes #24675
- [X] tests added / passed
- [X] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [X] whatsnew entry

---

The fix basically amounts to changing `self._codes` --> `cat._codes` in the code block below:
https://github.com/pandas-dev/pandas/blob/caf462c2a7699daf4b149d49f5aeaff822700113/pandas/core/arrays/categorical.py#L850-L855

Since the new object is being referred to as `cat` instead of `self`, the existing version didn't actually change the `_codes` of the resulting object.  The segfault would occur when try to view the resulting `Categorical`, as you'd have `take_1d` trying to take out of bounds `_codes` here:

https://github.com/pandas-dev/pandas/blob/caf462c2a7699daf4b149d49f5aeaff822700113/pandas/core/arrays/categorical.py#L1297


thanks @jschendel 