The powers of $5$ modulo $7$ obviously form a finite set. So one can try and look at a few values in order to get the idea:
\begin{alignat}{2}
5^0&\equiv 1&&\pmod{7}\\
5^1&\equiv 5&&\pmod{7}\\
5^2&\equiv 5\cdot 5\equiv 25\equiv 4&&\pmod{7}\\
5^3&\equiv 4\cdot 5\equiv 20\equiv 6&&\pmod{7}\\
5^4&\equiv 6\cdot 5\equiv 30\equiv 2&&\pmod{7}\\
5^5&\equiv 2\cdot 5\equiv 10\equiv 3&&\pmod{7}\\
5^6&\equiv 3\cdot 5\equiv 15\equiv 1&&\pmod{7}
\end{alignat}
Oh, good! Each time we have power $6$ we can reduce it to $1$ (modulo $7$). Since
$$
2017=6\cdot 336+1
$$
we are done! Indeed, $5^{2017}=(5^6)^{336}\cdot 5\equiv 1^{336}\cdot 5\equiv 5\pmod{7}$.
Fermat's little theorem, or, better, the Euler-Fermat theorem, is a generalization:
Theorem (Euler-Fermat). If $\gcd(a,n)=1$, then $a^{\varphi(n)}\equiv 1\pmod{n}$. In particular, if $p$ is prime and $p\nmid a$, then $a^{p-1}\equiv 1\pmod{p}$.
Here $\varphi$ is Euler's totient function: $\varphi(n)$ is the number of integers in the range $[0,n-1]$ which are coprime to $n$. For $p$ a prime, we obviously have $\varphi(p)=p-1$.
In case the prime is big, it would be a nuisance to compute all the powers like I did above for $7$.
Little Fermat's theorem is
Theorem (Fermat). If $p$ is prime, then $a^p\equiv a\pmod{p}$, for every integer $a$.