I was thinking that the ToF sensor would measure the distance to the pipe and the stepper would move it up from a home position until you get a local maximum, representing the distance you can use to calculate the OD.
The ToF sensors I see for hobby purposes (such as the Adafruit stuff), don't seem accurate enough for your purposes. I expect more precise examples exist though.