By using Fermat's Little Theorem, if $p$ is a prime number, then
$a^{p-1} \equiv 1 \text{ mod } p$.
$a^{p-1} \text {mod} p=1$
So, $3^{4} \text{ mod } 5 = 1 $.
$3^{48} \text{ mod } 5 = 3^{12 \times 4} \text{ mod } 5 =1 $.
Now $3^{51} \text{ mod } 5 = (3^{48} \text{ mod } 5) \times (3^3 \text{ mod } 5 )= 3^3 \text{ mod } 5 = 27 \text{ mod } 5= 2$