I’m not sure what a Walschaerts valve gear is, but I’m sure I warned everyone at the start of the series that I was not a “train nutter”, as my friend, Clockmender (who IS a train nutter) likes to call them.
I have two bits of good news for you. You did nothing wrong and there is an easy fix to the flipping.
There seems to be a quirky bug in the IK constraint when it is affecting a single bone. I was able to reproduce the same flipping issue in some other files.
First, to fix the flipping, delete the IK constraint and replace it with a Damped Track instead. Done!
The Damped Track seems to be more robust and resistant to the flipping.
I’m not 100% sure that the IK flipping is/would be considered a bug. It only appears to flip the bone when the parent bone is rotated 180.4 - 180.60 degrees. (I can’t tell the exact percentage of a degree because Blender stops counting in decimals above 100 degrees.) You were (un)lucky enough that the animation on the drive wheel had the bone rotated to this weird number on a frame instead of in between frames.
Anyways, good luck from here on out. I’ll need to make an amendment to the series to explain the fix. (I have another solution as well, but it requires a bit more effort and explanation.)
When I record the amendment tutorial, I’ll post it here, if anyone else is interested.