You can formulate this problem as an orthogonal Procustes problem: $$ \min_{X \text{ orthogonal}} \|AX-B\|_F. $$
ConvertingWith a transpose you can convert from the notation in the Wikipedia page to this form,: the solution is $X=UV^T$, where $A^TB = U\Sigma V^T$ is an SVD;SVD, and a proof follows from manipulating the expression using the Frobenius (trace) inner product.