My right testicle hurts periodically, what could cause this?

Intermittent torsion. Intermittent torsion occurs when a testicle twists, this cuts off venous return from the testis. Spermatic cord spontaneously untwists with intermittent torsion. But persistent torsion lasting six hours or more can result in testicular necrosis and thus needs to be corrected asap. Pain can also be due to intermittent epididymitis. Frequent periodic pain ? Be vascular congestion. ?See a urologist.