Consider that a control qubit is $q_k$ and a target qubit is $q_{k+n}$ and you want to apply operator $U$ on the target qubit. Denote $N=2^{n+1}$. Then matrix representation of this controlled $U$ is
\begin{equation}
CU=
\begin{pmatrix}
I_{\frac{N}{2}} & O_{\frac{N}{2}} \\
O_{\frac{N}{2}} & I_{\frac{N}{4}} \otimes U \\
\end{pmatrix}
\end{equation}
In your case $U=Z=\begin{pmatrix}1 & 0 \\ 0 & -1\end{pmatrix}$, $k=0$ and $n=2$, so the matrix representation of operator $Z$ acting on $q_{2}$ controlled by $q_{0}$ is
\begin{equation}
\begin{pmatrix}
1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & -1 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 \\
\end{pmatrix}
\end{equation}