[proofplan]
We expand the error $\|f - p\|^2$ using orthogonality of $\{p_k\}$, complete the square in each coefficient $a_k$, and observe the minimum is attained uniquely when $a_k = \langle f, p_k \rangle / \langle p_k, p_k \rangle$.
[/proofplan]
[step:Expand $\|f - p\|^2$ and complete the square]
Write $p = \sum_{k=0}^n a_k p_k$ for undetermined coefficients.
Then
\begin{align*}
\|f - p\|^2 &= \|f\|^2 - 2\sum_{k=0}^n a_k \langle f, p_k \rangle + \sum_{k=0}^n a_k^2 \langle p_k, p_k \rangle,
\end{align*}
where the cross terms $\langle p_j, p_k \rangle$ vanish for $j \neq k$ by orthogonality.
Completing the square in each $a_k$:
\begin{align*}
\|f - p\|^2 &= \|f\|^2 + \sum_{k=0}^n \langle p_k, p_k \rangle \left(a_k - \frac{\langle f, p_k \rangle}{\langle p_k, p_k \rangle}\right)^2 - \sum_{k=0}^n \frac{\langle f, p_k \rangle^2}{\langle p_k, p_k \rangle}.
\end{align*}
Each squared term is non-negative and vanishes if and only if $a_k = c_k := \langle f, p_k \rangle / \langle p_k, p_k \rangle$.
Therefore the minimum is achieved uniquely at $a_k = c_k$ for all $k$, and the minimal error is
\begin{align*}
\|f - p\|^2 &= \|f\|^2 - \sum_{k=0}^n \frac{\langle f, p_k \rangle^2}{\langle p_k, p_k \rangle}.
\end{align*}
[/step]