Mechanism of spin reorientation in ErFeO3