It's not really different. Here as well you start by assuming that $f$ takes the same value at two places and show that then the places must be the same. However, the "places" are not simple numbers ($m,n$ if you start with $f(m)=f(n)$ as you say), but pairs of numbers (and so are the values). That is: You start with the assumption
$$\tag1 f(m,n)=f(m'n')$$
and try to show from this that $$\tag2(m,n)=(m',n'),$$ which is just the same as: $m=m'$ and $n=n'$ (this is the definition of equality of pairs).
So let's see: From $(1)$ we have $(3m+n,n^2)=(3m'+n',n'^2)$, i.e. $3m+n=3m'+n'$ and $n^2=n'^2$. From the latter we find $n=n'$ (as there are no negatives in $N$) and plugging this into the firstgives $3m=3m'$, i.e. $m=m'$. So we have indeed shown $(2)$.