Suppose $\mathbf{X}$ is a $n \times p$ matrix, $\mathbf{B}$ is a $p \times k$ matrix, and $\mathbf{A}$ is a $p \times k$ orthonomal matrix with $k<\min(p,n)$ such that $\mathbf{A}^T \mathbf{A}=I_{k \times k}$. Let $\mathbf{A}_{\perp}$ be any orthonormal matrix such that $\left[\mathbf{A} , \mathbf{A}_{\perp}\right]$ is $p \times p$ orthonormal.
Then I wonder why the following equality holds:
$$ \left\|\mathbf{X}-\mathbf{X B A}^T\right\|^2=\left\|\mathbf{X} \mathbf{A}_{\perp}\right\|^2+\|\mathbf{X} \mathbf{A}-\mathbf{X B}\|^2 $$