This is from https://courses.cs.washington.edu/courses/cse311/14au/slides/lecture12-filled.pdf,
This procedure is used to solve a modular exponentiation problem, say

Here is the procedure 
How do you get from the first step to the second step?
To get $a^2$ mod m on the left side, I would multiply both sides of the first step by a to get
$a^2$ mod m $\equiv a^2$ (mod m )
How do i get from that to $(a $mod m$)^2$ mod m?
We use the following lemma. If $x\equiv a \pmod{m}$ and $y\equiv b\pmod{m}$ then $xy\equiv ab\pmod{m}$. This may already have been proved in your course. If it has not, here is a quick proof. We want to show that $m$ divides$xy-ab$. Note that $$xy-ab=x(y-b)+b(x-a).$$ Since $m$ divides $y-b$ and $m$ divides $x-a$, the result follows.
We use the above lemma, taking $b=a$ and $x=y=a\bmod{m}$. We get $$(a\bmod{m})^2\equiv a^2\pmod{m}.$$ Thus the left side and the right side have the same remainder on division by $m$. It follows that $$(a\bmod{m})^2\bmod{m}=a^2\bmod{m},$$ which is what we wanted to show.
The result about $a^4\bmod{m}$ is proved in the same way.