Let us consider the analogous question for linear operators. Given a diagonalizable operator $T \colon V \rightarrow V$ with eigenvalues $\lambda_1, \ldots, \lambda_s$ of multiplicities $k_1, \ldots, k_s$ respectively, denote by $V_i = \ker(T - \lambda_i \cdot \operatorname{id})$ the corresponding eigenspaces. Consider the subspaces
$$ D = \{ S \in \operatorname{Hom}(V,V) \,\, | \,\, S(V_i) \subseteq V_i \,\,\, \forall 1 \leq i \leq s \}, \\
C = \{ S \in \operatorname{Hom}(V,V) \,\, | \,\, ST = TS \}. $$
If $S$ commutes with $T$, then each $V_i$ is $S$-invariant so $C \subseteq D$. On the other hand, if $S \in D$ then because $V_i$ are both $T$ and $S$ invariant and $T$ acts on $V_i$ as $\lambda_i \cdot \operatorname{id}$, we have
$$ (ST)|_{V_i} = S|_{V_i} \circ T|_{V_i} = S|_{V_i} \circ (\lambda_i \cdot \operatorname{id})|_{V_i} = (\lambda_i \cdot \operatorname{id})|_{V_i} \circ S|_{V_i} = T|_{V_i} \circ S|_{V_i} = (TS)|_{V_i}. $$
Since $V = \bigoplus_{i=1}^s V_i$, this shows that $TS = ST$ and so $S \in C$ and $C = D$.
Finally, by choosing bases for $V_i$ we see that each $S \in D$ is represented by a block diagonal matrix with blocks of size $\dim V_i = k_i$ which implies that $\dim C = \dim D = \sum_{i=1}^s k_i^2$.