$\newcommand{\rank}{\mathrm{rank}}$
$\newcommand{\tr}{\mathrm{tr}}$
$\newcommand{\real}{\mathbb{R}}$
$\newcommand{\eps}{\epsilon}$
Write the linear model in the matrix form
\begin{align*}
y = X\beta + \epsilon
\end{align*}
where $y \in \mathbb{R}^n, X = \begin{pmatrix} x_1 & \cdots & x_{p}\end{pmatrix} \in \mathbb{R}^{n \times p}, \beta \in \mathbb{R}^p, \epsilon \in \mathbb{R}^n$. By convention, $x_1 \equiv e$, where $e \in \real^n$ is a column vector of all ones, and $\rank(X) = p$.
Recall that $H = X(X'X)^{-1}X'$ is the "hat matrix", and the residual vector can be written as $\hat{\epsilon} = (I_{(n)} - H)y$. First note that $y$ lies in $\mathbb{R}^n$, therefore $\hat{\epsilon}$ lies in the image space of the matrix $I_{(n)} - H$ (you can view the matrix $I_{(n)} - H$ as a linear operator on $\mathbb{R}^n$), say $U$. Linear algebra theory asserts that $\dim(U) = \rank(I_{(n)} - H)$. On the other hand, since $I_{(n)} - H$ is idempotent (i.e., $(I_{(n)} - H)^2 = I_{(n)} - H$), its rank is equal to its trace, i.e.,
\begin{align*}
& \rank(I_{(n)} - H) = \tr(I_{(n)} - H) = \tr(I_{(n)}) - \tr(H) \\
= & n - \tr(X(X'X)^{-1}X') = n -
\tr(X'X(X'X)^{-1}) = n - \tr(I_{(p)}) = n - p,
\end{align*}
where we used properties $\tr(A + B) = \tr(A) + \tr(B)$ and $\tr(AB) = \tr(BA)$ of trace.
There is another more geometric flavor argument to derive $\dim(U)$, as your textbook tries to convey. Denote the space spanned by columns of $X$ by $W$, then it is easy to see that
\begin{align*}
\real^n = W \oplus W^\bot, \tag{$*$}\label a
\end{align*}
where $W^\bot$ stands for the orthogonal complement of $W$. For any $y \in \real^n$, the decomposition
$$y = Hy + (I_{(n)} - H)y = \hat{y} + \hat{\eps}. $$
and $\hat{\eps}'Xa = y'(I - H)Xa = 0$ for any $a \in \real^p$ show that $\hat{\eps} \in W^\bot$, hence $U = W^\bot$. By $\eqref a$, it follows that
\begin{align*}
\dim(U) = \dim(W^\bot) = \dim(\real^n) - \dim(W) = n - p,
\end{align*}
since obviously $\dim(W) = \rank(X) = p$.