I am given the following theorem: Let $X\in\mathbf{K}^{n\times n}$ be a block partitioned matrix $X=\left[\begin{array}{c|c}A & B \\ \hline C& D \end{array} \right]$ with $A\in\mathbf{K}^{k\times k}$ and $D\in\mathbf{K}^{\ell\times \ell}$, then $\Pi^{-1} X\Pi=\left[\begin{array}{c|c}D & C \\ \hline B& A \end{array} \right]$ using $\Pi=\left[\begin{array}{c|c}0 & {\rm Id}_{\ell} \\ \hline {\rm Id}_{k}& 0 \end{array} \right]$. Of course this is easy to check given that $\Pi^{-1}=\Pi^\top$.
My book gives the following example of a similarity transformation using a $\Pi$ given a block partitioned matrix that consists of 9 blocks:
I am trying to understand what happens here, although I am not able to generalize the result from the theorem into the $3\times 3$-case. Could someone help clarify?

To do this problem you'd want an additional theorem. Keep $X$, $A$, etc. as above, but compute $\Pi^{-1}X\Pi$ for a permutation matrix of the form \begin{equation} \Pi = \left[\begin{array}{c|c} \Pi_k & 0\\ \hline 0&\mathrm{Id}_l\end{array}\right], \end{equation} where $\Pi_k$ is a $k \times k$ permutation matrix. You can use the formula you obtain as the first step in doing the stated problem. In the next step you can apply the theorem you were given to the $5 \times 5$ matrix $\Pi_k$ to finish the problem.