Rail-to-rail op-amp only reaches 90% of VCC, works sometimes, not everytime
You are exceeding the amplifiers input common-mode range.

It has rail-to-rail output but not rail-to-rail input. The allowable input range is -0.3V to +3.8V when fed from a 5V supply. When configured as a unity gain amplifier the output range will be limited by what's acceptable at the input.

Other posters have commented that the data sheet explicitly comments on the issue. (Datasheet)

If you exceed the CM input range the output can do almost anything but modern opamps are usually well-behaved. It looks like this one just clamps the output voltage.



You can't use it as a unity gain amplifier in this application.

If you made the gain about 1.5 or more it would work as the input would never get above the 3.8V limit before the output hit the power rail. Or find a pin-compatible amplifier with a wider range of input.

Since you have sensibly included the option of additional components on your PCB you could correct the problem without changing the PCB.

You can configure R53 and R54 to provide the 1.5 gain (e.g R53=10k, R54=4.7k)

Also you could add resistors R51 and R52 to attenuate the input by the same factor so the overall system works as designed.

All of the above unfortunately doesn't explain why some of your boards work all the way to the supply rail.