This algorithm terminates after a constant multiple of n steps. In the algorithm, we have two traversals occuring simultaneously.
The first traversal involves A and traverses the entire polygon exactly one time (recall that we stop when A = p1).
The second traversal starts at B = p2 and searches for a local maximum for A each time we advance A to its next neighbor. When it stops temporarily, we assign C its current position. It restarts where it left off at B = C each time we repeat the loop step. The second traversal is always ahead but not more than n - 1 points ahead of the first traversal. It starts at B = p2, one point ahead of A = p1 and remains ahead because A cannot be its own local maximum. It doesn't, however, get more than n - 1 points ahead because the transition from n - 1 points to n points ahead can never occur. If this were to occur then we would have compared the distance between A and its previous neighbor to the distance between A and itself and found that A was closer to its neighbor than it was to itself. This is impossible.
So, since the first traversal visits exactly n points and the second traversal is at most n - 1 points ahead, then the second traversal can visit at most n + n - 1 points. Put together, the algorithm uses a total of 3n - 1 steps.