The real problem is in the transition from lines 3 to 4, in which it appears that they are taking the square root of both sides. You cannot do this, as there are two solutions to any square root (for example, the square root of 9 is both 3 and -3).

The third line is correct:

(3-4)^2 = (-1)^2 = 1

(5-4)^2 = (1)^2 = 1

But it is dependent on the fact that 1 has square roots of both 1 and -1.