The problem is that a global ordering is defined on any Prolog term, including variables. A variable is smaller than any non-variable. But variables can stop being variables, jumping to any place within the global ordering. So while a “Prolog variable is immutable”, binding a variable does mutate it, at least in respect to the standard order.
When you unify two variables to each other they also become identical, which they weren’t before that.
This is of course all explained in the docs on the standard order of terms.