How can unifying 2 sentences in first-order logic result in a variable becoming 2 different things?
The variables called x in the two sentences are not related. We can rename them to make it clear:

~Loves(x1,F(x1)) v Loves(G(x1),x1)
~Animal(x2) v Loves(Jack,x2)


Now when matching ~Loves(x1,F(x1)) and Loves(Jack,x2), you can see you'll get Jack/x1, F(Jack)/x2 and the final result as in the book.