When I save a user account as an admin, I get logged in as that user I'm experiencing a strange issue that I'm having a really hard time debugging.

When I save a user account (of an authenticated user) as an admin, the account is saved, but when the page reloads I get an access denied and I am suddenly logged in as the user I saved, not the admin.  This happens whether I save the account in the UI (via the People page) or save the account using a rules action.

Recently, I added a custom function and modified a few of my rules, so these changes are likely to be the cause of the problem.  The site is version-controlled using git, so I can roll back to a working version, but I would like to attempt to determine what I did wrong.

I have Netbeans working with Xdebug.  I just don't know where to set breakpoints or how otherwise to start looking for the source of this problem.
Can you re-produce the problem from CLI?

Using drush scr, bootstrap, login as user 1, save a new user, check if your ID changed.

If you can do this from CLI, git bisect can be very helpful in finding the commit that caused it.