I have these nodes set up. What I'm trying to achieve is, the first frame to be red (or any colour which starts from same colour and finishes on starting colour, and the last frame to be red. and the animation to cycle once through the colour spectrum between frame 0 to 50.
I think a more intuitive way to achieve that will be using "Combine Color" in "HSV" mode, and animating the Hue using a driver:
To support starting at any color, you can use a more complex formula like this:
fmod(frame/50+0.5, 1) - it again divided the
frame by $50$ to normalize the frame range to $0..1$ range, then offsets it by $0.5$ to start at that value, and since the range becomes $0.5..1.5$ half of it is invalid and results may vary (I expected it would get clamped but something else happens). The modulo divides it by one to take the fractional part, as on this graph:
Instead of using a complex driver like that, consider moving the driver to a separate value, and using the node system from there:
The second driver there is to automatically synchronize when you modify animation length (which might be something you don't want to do).
To sweep through an arbitrary loop of colours over a defined period, you could, for example, use an arrangement like this:
..using the E eyedropper tool to match the first and last stops on the Color Ramp. Clamp must be unchecked on the Map Range.
Here's another version, looping through all hues, starting at 'Color at 0':