Spin reorientation transition on the surface of a topological insulator