The flip is purely down to the aerodynamics of the rocket, which is (presumably) designed so the nose always points into the wind.
If you imagine launching the rocket at 45º then it will follow a parabola (ignoring slowing due to drag) with the nose pointing in the direction of motion. If you increase the angle to 89º then it still follows a parabola but the parabola is much narrower, and the rate the rocket flips over at the top much greater. As you increase the angle closer and closer to 90º the parabola gets narrower and narrower and the rocket turns over ever more rapidly at the top.
The point of all this is that the straight up and down flight at 90º is still a parabolic curve, but in the limit where the parabola has zero width. If we extrapolate from the wider parabolae then in the straight up and down flight the rocket would flip over infinitely quickly. Obviously in practice the air resistance and moment of inertia of the rocket means the flipover will take a finite time. How long it takes will depend on the design of the rocket.