(Taking $\pi = \mathbb{Z} $ one obtains initial claim.) Here on MO Benjamin Steinberg provided nice proof based on Cauchy-Frobenius-Burnside orbit counting lemma.
Question: Is there any generalization of these relations to semigroups $G$ monoids/semigroups? In particular to a semigroup of ALL (non-necessarily non-degenerate) matrices over finite field $F_q$ ? Or for $G$ - ALL (non-necessarily bijective) maps of finite set to itself ? (The later is a kind of "field with one element" version of the previous).
Remark: If one counts pairs of elements: one from monoid another from group - then answer is positive - Benjamin Steinberg here on MO. However positive news may be finished here.
Remark: I vaguely remember Benjamin Steinberg some years ago explained here on MO that there can be several definitions of "conjugacy classes" for semigroups, cannot find that post now. There is a paper on that arxiv1503 (thanks to David A. Jackson). So it might work for some and may not work for others.
So $p^2+p$ for $n=2$, $p$ - classes of scalar matrices, $p^2$ with "full" "Frobenius cell" (i.e. [[0,1],[,]]).
Further no-go examples 3x3 commuting pairs of matrices: $p^{12}+p^{11}+2p^{10}-2p^8-2p^7+p^5 $ - not factorizable. In comments Benjamin Steinberg provided examples of semigroups where number of commuting elements is not factorizable in product.
So to conclude: it seems easy factorization of number of commuting pairs to anything is impossible for even simple monoids. So the only hope might be some more complicated summation of products like cardinality of some subgroups multiplied on cardinality some conjugacy classes, where summation over some filtration - how far elements are from the invertible ones.