There is an internal SetDirty function in PlayerSettings. No idea if it’ll actually make the change stick - usually in Unity forgetting to set dirty makes values not save, it doesn’t revert them, so I suspect something else is happening.
I stumbled upon this thread during my own issue incrementing the bundle version code from script for Android during the build process. I was explicitly setting the bundle version code based on some date logic so it’s always increasing and I was seeing it being properly updated via debug lines during the build process, but after checking the player settings in the build profile it was never actually updated. It was always staying at 1.
After a ton of research and debugging to no avail, I finally figured out by some fluke that it would not persist if the value was 1 originally. It seems like a Unity bug, so I thought I would post it here so it can be fixed for others. Once I set the value to 2 my build processing script was finally working properly.