Stability of relative equilibria in arbitrary axisymmetric gravitational and magnetic fields