Using some group theory, the result can be easily generalized as follows:
If $R$ is an infinite commutative ring such that $SL_n(R)$ is perfect (i.e.
$SL_n(R)$ is its own commutator) then the only polynomial functions $p: R[x_{11},...,x_{nn}] \to R$ satisfying the
required identities are $p(X) = \det(X)^n$ for some $n\ge 0$.
Examples for $R$ are all (infinite) local rings (in particular fields) and principal ideal domains.
Proof: $p$ induces a group homomorphism $p: GL_n(R) \to R^\times$ those kernel contains the commutator subgroup. Since $SL_n(R)$ is perfect, $SL_n(R) \le \ker(p)$. Define a group hom.
$$f: R^\times \to R^\times,\; x \mapsto p\big(\operatorname{diag}(x,1,...,1)\big).$$
If $A \in GL_n(R)$, set $B := \operatorname{diag}(\det(A),1,...,1)$. Then $AB^{-1} \in SL_n(R)$ implies
$$p(A)=p(B)=f(\det(A)).\hspace{70pt}(\ast)$$
Since $p$ is a polynomial function, $f(x)$ is a polynomial function in $x$ satisfying
$$f(xy)=f(x)f(y).\hspace{110pt}(\ast\ast)$$
As $R$ is infinite, it's easy to see that the only polynomial functions with $(\ast\ast)$ are $f(x)=x^n$. Now the result follows from $(\ast)$. q.e.d.