There is a more generalized version of Hilbert's Projection Theorem (HPT) for convex sets which says:
Suppose that $H$ is a Hilbert space and $V \subset H$ is a nonempty, closed convex set. Let $x \in H$ such that $x \notin V $.
(a) Prove that there is a unique $y \in V$ such that $\|x − y\|$ is minimal.
(b) If $V$ is a linear subspace, prove that $x − y$ is orthogonal to $V$.
How can I use the HPT (with closed subspaces) to prove the more generalized version?
Let $d=d(x,V)$ and $x_{n}\in V$ be such that $\|x_{n}-x\|\rightarrow d$, then \begin{align*} \|x_{n}-x_{m}\|^{2}&=\|(x_{n}-x)-(x_{m}-x)\|^{2}\\ &=2(\|x_{n}-x\|^{2}+\|x_{m}-x\|^{2})-\|(x_{n}-x)+(x_{m}-x)\|^{2}\\ &=2(\|x_{n}-x\|^{2}+\|x_{m}-x\|^{2})-4\left\|\dfrac{x_{n}+x_{m}}{2}-x\right\|^{2}\\ &\leq 2(\|x_{n}-x\|^{2}+\|x_{m}-x\|^{2})-4d^{2}\\ &\rightarrow 2\cdot 2d^{2}-4d^{2}\\ &=0. \end{align*} The completeness of $H$ gives some $y\in H$ such that $\|x_{n}-y\|\rightarrow 0$, but then $\|y-x\|=\lim_{n}\|x_{n}-x\|=d$.
Assume that $z\in V$ is such that $\|z-x\|=\|y-x\|=d$, then sequence $(\alpha_{n})=(y,z,y,z,...)$ is such that $\|\alpha_{n}-x\|=d$, by the reasoning just proved, $(\alpha_{n})$ is Cauchy, then we must have $z=y$.
Now we are to show that $\left<x-y,z\right>=0$ for every $z\in V$. Let $v=x-y$ for simplicity, and consider any scalar $a$, then $y+az\in V$ and hence \begin{align*} d^{2}\leq\|x-(y+az)\|^{2}=\|v-az\|^{2}=\|v\|^{2}+|a|^{2}\|z\|^{2}-2\text{Re}(a\left<z,v\right>). \end{align*} Let $a=\left<v,z\right>/\|z\|^{2}$ we get \begin{align*} d^{2}\leq d^{2}+\left|\left<v,z\right>\right|^{2}-2\left|\left<v,z\right>\right|^{2}, \end{align*} and hence $\left|\left<v,z\right>\right|^{2}\leq 0$, so $\left<v,z\right>=0$, as expected.