Looping Back to setup after void loop() has run a random number of times

Probably because the processor is resetting after some period of time. If that's true then the cause could be electrical noise or something in the code causing it to crash. Electrical noise comes from problems with circuit design or construction, to investigate this we'd need at least a schematic and photos of your project. I leave problems with your code to others.