I've tested with the project provided for repro purposes but I found a problem in the code provided.
The code uses mouse.ispressed to trigger the setting change. mouse.ispressed is true for as long as the mouse button is held so depending on how slow one clicks it can set it to true and false repetitively. Changing it to mouse.wasClickedLastFrame resolves this issue.
Therefore the issue was caused by usage of the wrong event type and is not a bug.