This is Fuglede's theorem. From the spectral theorem, $A$ can be written as
$$A=\sum_{i=1}^{n}\lambda_iP_i,$$
and $A^{*}$ can be expressed similarly by replacing $\lambda_i$ by its conjugate. Now, notice that for $p_i(x)=x\prod_{j : \lambda_j \neq \lambda_i}(x-\lambda_j)$
$$p_i(A)=\sum_{j=1}^{n}p_i(\lambda_j)P_j=\lambda_i\prod_{j : \lambda_j \neq \lambda_i}(\lambda_i-\lambda_j)\sum_{j : \lambda_j=\lambda_i}P_j.$$
(The first equality is a generalization of the fact that $A^k = \sum_{i=1}^{n}\lambda_i^kP_i$.) This implies that
$$\lambda_i\sum_{j : \lambda_j=\lambda_i}P_j=\frac{p_i(A)}{\prod_{j : \lambda_j \neq \lambda_i}(\lambda_i-\lambda_j)}.$$
Given that A and B commute, we have that $p_i(A)$ and $B$ also commute. So,
$$\lambda_i\sum_{j : \lambda_j=\lambda_i}BP_j=\lambda_i\sum_{j : \lambda_j=\lambda_i}P_jB,$$
and by replacing $\lambda_i$ with its conjugate and summing over all distinct eigenvalues we get that $BA^{*}=A^{*}B$.