You can define an image point (or set origin point) on the shape sprite at the yellow dot:
And then compare two angles: player movement angle, and the angle between the player and the yellow dot.
If angle1=angle2, then rotation is not required.
If angle2 is clockwise from angle1, rotate 90 degrees.
If angle2 is counterclockwise from angle1, rotate 90 degrees.
.
You can add another condition "the difference is over 5 degrees", to avoid rounding errors.
Thanks for the answer, I kind of understood your idea, but I didn't understand at all how to implement it. If you have the opportunity to make a small source code, I would be very grateful.