I unfortunately experienced a similar issue which eventually resulted in my being forced to resort to Samsung's factory warranty...not once but twice...turned out being a intermittent short within my factory samsung charging cable..basically heated the phone internally eventually melting the circuit to the rear camera. After troubleshooting the cause after receiving phone number 3, I determined that any use while charging taxed the transformer causing it to heat up severely which over time damaged the cable and eventually killing the cam circuit... one way to test yours would be to go into settings, battery, and disable (fast charge)... if problem goes away, replace your charger/cables for equipment. if it remains, it most likely damaged the charging circuit (resistance usually makes it intermittent preceding complete failure.).any other cable will work and for the transformer. Any 5.0vdc at 2000mah will work for normal charging if using fast charge you need one that supports the technology (look for "adaptive fast charging label) throttles voltage up to 9vdc while slightly reducing the current...
as a final note: if you don't wanna replace your phone every few weeks, I strongly recommend using fast charge mode with your device powered off... Samsung engineers seriously dropped the ball calculating the current /heat.