Welcome to the forums @Phil_Violated!
My guess is that it's probably due to how Godot handles rotation over 180
degrees. My hunch is that when the Y rotation is over 180 degrees and the X rotation is around 90, it will flip it from 180
to -180
on the Y, which could be affecting the X axis too. That is probably why the clamp is causing it but not the rotating, since the rotate_x
function just adds an offset and so it doesn't matter if its positive or negative.
You can see this if you rotate an object in the Godot editor on multiple axis, rotating one over 180 will flip it to negative and this can also flip/change the rotation in the other axes as well.
I agree with DaveTheCoder though, I would suggest printing the values and seeing if the numbers help show what is causing the issue.
If the issue is that the rotation is flipping when over 180, then I might suggest parenting your Camera node to a Spatial, and then rotate the Spatial on just one axis and the camera on just the other axis. That way, the rotation shouldn't have the issue where it suddenly changes when one of the axes gets over 180, as one one axis is being modified at a time.