Why is "division by $(z-1)$" valid here?
You can first note that the implication is true for $x=0$ by checking it. Then you can say you still have to prove it for $x\neq 0$, but then you can divide by $x$.
This is a consequence of the fact that a nonzero polynomial whose coefficients are complex numbers (or in any integral domain) has no more roots than its degree. This quickly yields what we seek, viz.
Theorem $ $ If $\,f,g,h\,$ are polynomials with coefficients in $\Bbb C$ (or any infinite field C) and $\,f\neq 0\,$ then
$$\begin{align} f(x) g(x) &= f(x) h(x)\ \ \text{for all }\, x\in C\\ \Rightarrow\ \ g(x) &= h(x)\qquad\ \ \text{for all }\, x\in C\end{align}$$
Proof $\ $ Since $\,f\neq 0\,$ it has only finitely many roots (at most $\deg f).\,$ Thus there are infinitely many nonroots $\,c\in C\,$ where $\,0\neq f(c)\,$ so it is cancellable, thus
$$f(c)\,(g(c)-h(c)) = 0\,\Rightarrow\, g(c)-h(c) = 0$$
Thus the polynomial $\,g(x)-h(x)\,$ has infinitely many roots $\,x = c\,$ so it is identically zero.
Remark $ $ It fails for finite fields, e.g. over $\,\Bbb Z_3 = $ integers $\!\bmod 3\,$ we have $ x(x^2) = x(1)\,$ for all $\,x,\,$ but $\, x^2 = 1\,$ is false at $\,x = 0$.
For an alternative perspective, consider that the polynomials you are looking at can be thought of as purely formal objects without analytical meaning. Don't think of the polynomials as polynomial functions that you need to worry about being $0$ when you plug in different values of $x$, but as algebraic objects belonging to the ring of polynomials $\mathbb C[x]$.
Then your problem disappears because the ring of polynomials over $\mathbb C$ is an integral domain, meaning that for $f(x),g(x)\in\mathbb C[x]$, if $f(x)g(x)=0$ (importantly: here $=$ is a polynomial equality, not an equality of complex numbers), then either $f(x)=0$ or $g(x)=0$. You can prove this property in many ways. In fact, it is true that $R[x]$ is a domain whenever $R$ is, and $R$ does not need to be a field like $\mathbb C$. One nice way is to consider the leading coefficients of two nonzero $f(x),g(x)$ in the ring of polynomials: since the leading coefficients are nonzero, then their product is nonzero (because the ring of coefficients is a domain) so the polynomial product is nonzero too.
How does this tie in with the usual concept of polynomial functions? Well, for any $\alpha\in\mathbb C$, there exists a unique homomorphism $\phi_\alpha:\mathbb C[x]\to\mathbb C$ that sends $x$ to $\alpha$, called the evaluation homomorphism. This homomorphism essentially gives you a way to "plug in" the value of $\alpha$ into a formal polynomial, recovering the idea of a function. But since we have dealt with the issue of division by zero within the ring of polynomials where division by zero is a non-issue, we are now safe, because two polynomials that are formally equal define the same function over $\mathbb C$.