Note that the plane passes through the origin. In order to find the projection matrix that projects onto the line orthogonal to the plane (i.e., the line spanned by the vector $\bf n$) and passing through the origin, consider the following $1$-dimensional least-squares problem$^\color{magenta}{\star}$
$$ t_{\min} := \arg\min_{t \in {\Bbb R}} \| {\bf x} - t \, {\bf n} \|_2^2 = \dots = \frac{{\bf n}^\top {\bf x}}{{\bf n}^\top {\bf n}}$$
and, thus,
$$ t_{\min} \, {\bf n} = \left( \frac{{\bf n}^\top {\bf x}}{{\bf n}^\top {\bf n}} \right) {\bf n} = {\bf n} \left( \frac{{\bf n}^\top {\bf x}}{{\bf n}^\top {\bf n}} \right) = \underbrace{\left( \frac{\,\,{\bf n} \, {\bf n}^\top }{{\bf n}^\top {\bf n}} \right)}_{=: {\bf P}} {\bf x} = {\bf P} \, {\bf x} $$
is the point on the line that is closest (in the Euclidean norm) to a general ${\bf x} \in {\Bbb R}^d$, i.e., it is the orthogonal projection of $\bf x$ onto the line. Since we have a matrix-vector multiplication, $\bf P$ is the projection matrix that projects onto the aforementioned line and
$$ {\bf I}_d - \dfrac{\,\,{\bf n} \, {\bf n}^\top}{{\bf n}^\top {\bf n}} $$
is the projection matrix that projects onto the orthogonal complement of the aforementioned line, i.e., the plane itself.
$\color{magenta}{\star}$ Note that one does not even need calculus to find $t_{\min}$. From $ \| {\bf x} - t \, {\bf n} \|_2^2 = {\bf x}^\top {\bf x} - 2 t \,{\bf n}^\top {\bf x} + t^2 {\bf n}^\top {\bf n} $ and using the quadratic formula, one obtains $t_{\min} = \frac{{\bf n}^\top {\bf x}}{{\bf n}^\top {\bf n}}$.
least-squares