Origin of spin reorientation in rare earth-iron-boron permanent magnets