Let $G$ be a group of order 3, $G=\langle g\rangle$ and let $H$ be a group with an element h of order 4. Let $f: G\longrightarrow H$, where $f(g^i)= h^i$. Then f is not an homomorphism because $f(g^3)= h^3$ but $g^3= 1$ and $h^3 \neq 1$. However
$$\begin{align} f(g^ig^j)&= f(g^{i+j})\\ &= h^{i+j}\\ &= h^i h^j\\ &= f(g^i)f(g^j). \end{align}$$
Where is the mistake?
In particular $f(gg^2)=f(g^3)=h^3=hh^2=f(g)f(g^2)$.
That map $f$ doesn't make sense. Note that $g^4=g$, but $f(g^4)\neq f(g)$.