In general, $\hat{\boldsymbol{\mu}} \neq (-g_J \mu_\text{B}/\hbar) \hat{\mathbf{J}}$ as operators. Indeed, unless the g-factors of the individual angular momenta are the same, the two operators cannot be proportional since $\hat{\mathbf{J}} = \hat{\mathbf{L}} + \hat{\mathbf{S}}$. The equality holds foris between their matrix elements with respect to the eigenstates of the $z$-component of the total angular momentum for a given $j$. So $$\langle j,m'_j| \hat{\boldsymbol{\mu}}|j,m_j\rangle = -g_J \frac{\mu_\text{B}}{\hbar} \langle j,m'_j|\hat{\mathbf{J}}|j,m_j\rangle$$ but this does not mean that $$\hat{\boldsymbol{\mu}} = -g_J \frac{\mu_\text{B}}{\hbar} \hat{\mathbf{J}}.$$