This theorem may be surprising but if we check the sizes of the matrices involved, then maybe it will not seem so far-fetched. First, $AB$ has size $m\times p$, so its transpose has size $p\times m$. The product of $\transpose{B}$ with $\transpose{A}$ is a $p\times n$ matrix times an $n\times m$ matrix, also resulting in a $p\times m$ matrix. So at least our objects are compatible for equality (and would not be, in general, if we did not reverse the order of the matrix multiplication).
Here we go again, entry-by-entry. For $1\leq i\leq m$, $1\leq j\leq p$, \begin{align*} \matrixentry{\transpose{(AB)}}{ji}=&\matrixentry{AB}{ij} &&\knowl{./knowls/definition.TM.knowl}{\text{Definition TM}}\\ &=\sum_{k=1}^{n}\matrixentry{A}{ik}\matrixentry{B}{kj} &&\knowl{./knowls/theorem.EMP.knowl}{\text{Theorem EMP}}\\ &=\sum_{k=1}^{n}\matrixentry{B}{kj}\matrixentry{A}{ik} &&\knowl{./knowls/property.CMCN.knowl}{\text{Property CMCN}}\\ &=\sum_{k=1}^{n}\matrixentry{\transpose{B}}{jk}\matrixentry{\transpose{A}}{ki} &&\knowl{./knowls/definition.TM.knowl}{\text{Definition TM}}\\ &=\matrixentry{\transpose{B}\transpose{A}}{ji} &&\knowl{./knowls/theorem.EMP.knowl}{\text{Theorem EMP}} \end{align*}
So the matrices $\transpose{(AB)}$ and $\transpose{B}\transpose{A}$ are equal, entry-by-entry, and by the definition of matrix equality (Definition ME) we can say they are equal matrices.