5. In the cube $A B C D-A_{1} B_{1} C_{1} D_{1}$, $E$ and $F$ are the midpoints of edges $A A_{1}$ and $B B_{1}$, respectively, and $G$ is a point on $B C$. If $D_{1} F \perp F G$, then the angle between line $C_{1} F$ and line $E G$ is $(\quad)$.
(A) $\frac{\pi}{3}$
(B) $\frac{\pi}{2}$
(C) $\frac{5 \pi}{6}$
(D) $\frac{2 \pi}{3}$
5.B.

As shown in Figure 2, establish a coordinate system, and let the side length of the cube be 1. Then $E\left(1,0, \frac{1}{2}\right), F(1, 1, \frac{1}{2}), G(m, 1,0)$,
$$
\begin{array}{l}
D_{1}(0,0,1), C_{1}(0,1,1), \\
\quad E G=\left(m-1,1,-\frac{1}{2}\right) .
\end{array}
$$

From $D_{1} F \perp F G$, we get $D_{1} F \cdot F G=0$.
Also, $D_{1} \boldsymbol{F}=\left(1,1,-\frac{1}{2}\right), F G=\left(m-1,0,-\frac{1}{2}\right)$, so $(m-1)+\frac{1}{4}=0$. Solving for $m$ gives $m=\frac{3}{4}$.
Thus, $E G=\left(-\frac{1}{4}, 1,-\frac{1}{2}\right)$.
Since $\boldsymbol{C}_{1} \boldsymbol{F}=\left(1,0,-\frac{1}{2}\right)$, we have $\boldsymbol{C}_{1} \boldsymbol{F} \cdot \boldsymbol{E} G=0$, which means $C_{1} F \perp E G$.
Therefore, the angle between line $C_{1} F$ and line $E G$ is $\frac{\pi}{2}$.