Evaluating $a^n \mathrm{~mod~}m$ is easy when $m$ is prime or $a, m$ are co-prime meaning $\gcd(a,m)=1$. But when $a, m$ are not co-prime, it's not easy to solve it. In this case, Repeated Squaring method can resolve it which needs just about $\lceil\log_2{n}\rceil$ steps. Although here, $3$ and $5$ are co-prime, I'm going to use repeated squaring method as it's the generalized one. For example, if the question asked $12^{100} \mathrm{~mod~}30$, Fermat's last theorem or Euler's Totient function $\varphi$ would not work. Therefore, Repeated Squaring method is the safest and the faster one in generalized case.
$3^{51} \mathrm{~mod~} 5\equiv 3\left(3^{25}\right)^2\mathrm{~mod~} 5 \tag{1}$
$3^{25} \mathrm{~mod~} 5\equiv 3\left(3^{12}\right)^2\mathrm{~mod~} 5 \tag{2}$
$3^{12} \mathrm{~mod~} 5\equiv \left(3^{6}\right)^2\mathrm{~mod~} 5 \tag{3}$
$3^{6} \mathrm{~mod~} 5\equiv \left(3^{3}\right)^2\mathrm{~mod~} 5 \tag{4}$
$3^{3} \mathrm{~mod~} 5\equiv 3\left(3^{1}\right)^2\mathrm{~mod~} 5 \tag{5}$
$3^{1} \mathrm{~mod~} 5\equiv 3\mathrm{~mod~} 5 \tag{6}$
Now evaluating in a bottom-up fashion,
no$(6)$ $\Rightarrow 3^{1} \equiv 3$
no$(5)$ $\Rightarrow 3^{3} \equiv 3\left(3\right)^2\equiv3\times9\equiv3\times4\equiv12\equiv2$
no$(4)$ $\Rightarrow 3^{6} \equiv \left(2\right)^2\equiv4$
no$(3)$ $\Rightarrow 3^{12} \equiv \left(4\right)^2\equiv16\equiv1$
no$(2)$ $\Rightarrow 3^{25} \equiv 3\left(1\right)^2\equiv3$
no$(1)$ $\Rightarrow 3^{51} \equiv 3\left(3\right)^2\equiv3\times9\equiv3\times4\equiv12\equiv2$
$\therefore 3^{51} \mathrm{~mod~} 5\equiv2$
Note: Here $\equiv$ means modular equivalence.