Proof (orthogonal projection matrix iff U U transpose)

Let $m=\mathrm{rank}(P)$.

Notice $U^T U = I_m$ since columns of $U$ are orthonormal. If $P = UU^T$, then it is symmetric and $P^2 = UU^TUU^T = UU^T = P$.

Conversely, let $\set{v_1, \ldots, v_m}$ be an orthonormal basis for the column space of $P$, and extend it to $\set{v_1, \ldots, v_m, \ldots, v_n}$ an orthonormal basis for $\R^n$. Form the matrix $$ \begin{align*} U = \pmat{v_1 & \ldots & v_m}. \end{align*} $$ We will show that $UU^T$ and $P$ agree on the basis.

For $1\leq i\leq m$, $v_i$ is in the column space of $P$, so say $v_i = Pw_i$. Then $Pv_i = P^2w_i = Pw_i = v_i$. This agrees with $$ \begin{align*} UU^T v_i = \pmat{v_1 & \ldots & v_m} \pmat{v_1^T \\ \vdots \\ v_m^T} v_i = \pmat{v_1 & \ldots & v_m} \v e_i = v_i \end{align*} $$ by orthonormality of $\set{v_1, \ldots, v_m}$.

Moreover for $m+1\leq i\leq n$, we have $Pv_i = P^T v_i = 0$ since $v_i$ is orthogonal to the column space of $P$. This agrees with $$ \begin{align*} UU^T v_i = \pmat{v_1 & \ldots & v_m} \pmat{v_1^T \\ \vdots \\ v_m^T} v_i = \pmat{v_1 & \ldots & v_m} \v 0 = \v 0. \end{align*} $$