Suppose we're given the following Hamiltonian: $$\hat{H}=\frac{\omega}{\hbar} \left(\hat{S}_+^2+\hat{S}_-^2\right)$$ Suppose also that we measure $\vec{S}^2$ and get $6\hbar^2$, i.e. reduced to the $s=2$ subspace, and want to find all the possible energies (aka the eigenvalues of the Hamiltonian operator in the relevant basis).
Obviously the relevant basis consists of the eigenstates $\{|2,m\rangle\}$ of the spin projection operator. I calculated the matrix elements of $\hat{H}$ in this basis and got the following $5\times 5$ matrix:
$$\hat{H}=\hbar \omega \begin{pmatrix} ~ & |2,2\rangle & |2,1\rangle & |2,0\rangle & |2,-1\rangle & |2,-2\rangle\\ |2,2\rangle & 0 & 0 & 2\sqrt{6} & 0 & 0\\ |2,1\rangle & 0 & 0 & 0 & 6 & 0\\ |2,0\rangle & 2\sqrt{6} & 0 & 0 & 0 & 2\sqrt{6}\\ |2,-1\rangle & 0 & 6 & 0 & 0 & 0\\ |2,-2\rangle & 0 & 0 & 2\sqrt{6} & 0 & 0 \end{pmatrix}$$
It can be shown that the eigenvalues are $E=\pm 4 \sqrt{3} \hbar \omega, \pm 6\hbar \omega , 0$, which is indeed correct. However calculating them was a little bit tedious.
Now, it turns out that there exists a simpler matrix representation of $\hat{H}$ in the same basis. It has to do with the special structure of the Hamiltonian which has both raising and lowering operators squared. This naturally splits the basis into two groups: $\{ |2,2\rangle, |2,0\rangle,|2,-2\rangle \}$ and $\{ |2,1\rangle, |2,-1\rangle \}$ which are closed under the actions of $\hat{S}^2_{\pm}$. We can thus re-order the basis and get the following block-diagonal form
$$\hat{H}=\hbar \omega \begin{pmatrix} ~ & |2,1\rangle & |2,-1\rangle & |2,2\rangle & |2,0\rangle & |2,-2\rangle\\ |2,1\rangle & 0 & 6 & 0 & 0 & 0\\ |2,-1\rangle & 6 & 0 & 0 & 0 & 0\\ |2,2\rangle & 0 & 0 & 0 & 2\sqrt{6} & 0\\ |2,0\rangle & 0 & 0 & 2\sqrt{6} & 0 & 2\sqrt{6}\\ |2,-2\rangle & 0 & 0 & 0 & 2\sqrt{6} & 0 \end{pmatrix}$$
which is very convenient because now in order to find the eigenvalues we can analyze two smaller matrices. Thankfully, the eigenvalues turn out to be the same.
Question: we know from linear algebra that, in general, swapping/changing the order of rows/columns (which is exactly what happened here) changes the eigenvalues. However in this case the eigenvalues remained the same. I understand the physical reason behind it, but how can it be justified mathematically? Suppose we knew nothing about the structure of the Hamiltonian (or, alternatively, weren't smart enough to recognize that the basis can be conveniently broken into two "special" subgroups). Is there a mathematical way of finding the "best" ordering of basis vectors such that the matrix representation of a given operator assumes a block-diagonal form? And is there a mathematical justification for why the eigenvalues remain the same after we change the order of rows/columns? Maybe it has to do with the fact that the matrix (operator) is symmetric (Hermitian)?