Say we have vectors $x$ and $y$ in some inner product vectorspace. Then the projection of $x$ onto $y$ is given by: $\begin{aligned}P(x)=x-\frac{x\cdot y}{\Vert y\Vert ^2}y\end{aligned}$, but I would think that I this can be rewritten as: $\begin{aligned}P(x)=x-x\frac{y\cdot y}{\Vert y\Vert^2}=x-x=0\end{aligned}$.
Obviously, that can't be right - so where am I making a mistake? I know I'm allowed to rewrite the projection as follows: $\begin{aligned}P(x)=x-x\left(\frac{y}{\Vert y\Vert}\right)\frac{y}{\Vert y\Vert} \end{aligned}$, so it seems that I'm allowed to mess around with the parentheses. So what is going on?
EDIT
Okay, so I should have written: $$P(x)=x-x\cdot\left(\frac{y}{\Vert y\Vert} \right)\frac{y}{\Vert y\Vert},$$ to make it clear that we are taking an inner product of $x$ and $y$, and later on we multiply some scalar with $y$.
$\textbf{Remark}$: I think your confusion arises in not knowing what $P(x)$ actually is. You said that it was the projection of $x$ onto $y$, but that's not right. Below I show you what $P(x)$ actually is and from there you'll quickly see why the manipulation is incorrect.
Mlc gives an answer in the analytical direction, but geometrically, why doesn't this make sense? This is just the first step in Gram S. orthonormalization, which is a construction starting with linearly independent vectors. The process gives you a way of producing a set of linearly independent and orthonormal vectors. I'll say more about that later, but again, we proceed with the assumption that $x,y$ are linearly independent.
$$ \underbrace{x \cdot \frac{y}{\|y\|}}_{\|x\| \cos \theta} \cdot \frac{1}{\|y\|}$$
And $\|x\| \cos \theta$ is the scalar component of the projection of $x$ onto $y$ and so we have,
$$w:=\left(x \cdot \frac{y}{\|y\|}\right) \cdot \underbrace{\frac{y}{\|y\|}}_{\textrm{unit vector}}$$
is the projection of $x$ onto $y$. Hence $u:=x - w$ is perpendicular to $x$ and $y$, the latter due to the fact that the head of $u$ lies on the line spanned by $y$. So your formula (which produces the vector $u$) is not the projection of $x$ onto $y$, it produces a vector orthogonal to $x,y$. And so there are a few reasons why the manipulation is incorrect, but most importantly, your rewrite would imply,
$$x \frac{y \cdot y}{\|y\|^2} = \frac{x\cdot y}{\Vert y\Vert ^2}y=\lambda y$$
However, the furthest equation the left hand side is just $x$, but since $x,y$ were supposed to be linearly independent, this can't be true. Another reason using this same approach, since the left hand side is just $x$ and $x,y$ are linearly independent, then $x \not = \lambda y$, but the original expression $w$ is a multiple of $y$.