Here $z$ = $x-y$, where $x$ is a fixed element of the Hilbert space which is not in $Y$, and $y$ is the unique closest element of $Y$ to $x$.
This is part of a question on an old prelim exam. So far I have already proved that there exists a unique closest element $y$ to $x$. But the final part of the problem is to prove that $x-y\perp Y$, and here I'm coming up short.
I've tried to expand the expression $\lVert z-ty \rVert^2$, where $t=\langle w|y\rangle$, since I found a somewhat related proof that uses this strategy. But this didn't seem to go anywhere for me.
Here's the idea: Take $w\in Y$, and imagine the triangle $\triangle xyw$. If $x-y$ was not orthogonal to $w-y$ (represented by the segments $\overline{xy}$ and $\overline{yw}$, respectively, then we would be able to find a new point in the line $\overleftrightarrow{yw}$ which would be closer to $x$, which contradicts our hypothesis. This point would be of the form $y+t(w-y)$
Now let's try to use the idea above. Instead of working with $w-y$, let's simply use $w$ (because $w-y\in Y$ iff $w\in Y$). By taking the contrapositive of the arguments above, we should start by using the hypothesis on $y$ with the line $y+tw$, and obtain the desired result.
Since $y$ is closest to $x$ in $Y$, and for all $t$ we have $y+tw\in Y$, then $$\Vert x-y\Vert^2\leq\Vert x-(y+tw)\Vert^2$$ for all $t\in\mathbb{C}$, or equivalently (with simple calculations) $$0\leq -2\operatorname{Re}t\langle x-y,w\rangle+|t|^2\Vert w\Vert^2$$ for all $t\in\mathbb{C}$. The "real part" is a little bothersome, so to get rid of it, consider only $t$ for which $t\langle x-y,w\rangle$ is real (namely, $t$ of the form $t=\alpha\overline{\langle x-y,w\rangle}$, with $\alpha\in\mathbb{R}$), so we obtain, for every $t\in\mathbb{R}$, $$2t\langle x-y,w\rangle\leq t^2\Vert w\Vert^2\tag{1}$$ Moreover, this is valid for all $t\in\mathbb{R}$, so the same equation is valid with $-t$ in place of $t$: $$-2t\langle x-y,w\rangle\leq t^2\Vert w\Vert^2\tag{2}$$ Putting $(1)$ and $(2)$ together, $$2|t||\langle x-y,w\rangle|\leq t^2\Vert w\Vert^2$$ or equivalently $$2|\langle x-y,w\rangle|\leq |t|\Vert w\Vert^2$$ for all $t\neq 0$ in $\mathbb{R}$ (because we divided by $|t|$). But letting $t\to 0$, we conclude that $$|\langle x-y,w\rangle|=0$$ which is precisely what we wanted.