Ant's answer is correct, but here's another way of saying the same thing, with a telling example.
Spivak's operation is in fact "legal," as you say, because it is just an instance of what a logician would call the "law of substitution."
As another example, presumably you know how a difference of squares factors:
$$x^2-y^2=(x-y)(x+y)$$
But this identity holds for all real numbers $x$ and $y$;
$x$ and $y$ can stand for whatever real number you want. So we should really think of this equation as shorthand for infinitely many different factorizations, each given by substituting a different value for $x$ and $y$. For example, substituting $x=a+b$ and $y=c+d+e$ gives the seemingly more difficult result
$$(a+b)^2-(c+d+e)^2=(a+b-c-d-e)(a+b+c+d+e)$$
But really this equation follows from the first by the substitution principle. That's exactly the sort of argument Spivak is giving here.