What is the mechanism behind recurring or looping thoughts? I'm interested in what is the mechanism that explains the recurrence or looping of thoughts within a person's mind. Unless very strongly distracted, such thoughts can creep up back or mutate slightly while maintaining the same overall theme - action is required. 

From my understanding both positive and negative thoughts can loop, although thoughts with the themes of fear, anxiety, compulsion or desire can be more disturbing when looping. 

What is the mechanism behind looping or recurring thoughts? In particular I'm interested if such thoughts are chemically induced through a release of some kind of neuromodulator (like fight or flight response is based on Adrenaline).

A few examples, where rational thought is used to counter irrational fear or anxiety thought:


Did I forget to do X? 
I really have to go to Y, but what if I did not do X?
[Imagination a horrible scenario when X is not done]
I better go check on X.
Check on X reassures the person, resulting in no new thoughts creeping in.


What interests me is what happens when the person either cannot go and check or will incur significant cost for doing so (ex: being late to work) or will try to resist the urge to check. In this case recurring thoughts can eventually reemerge and start to invade one's awareness:


Did I forget to turn the stove off?
I really have to go to work.
But the house can burn down 
I believe that nothing bad will come out of it
You can't know that
The stove has a pilot light - gas will just keep burning
But the cat can jump on a stove and get burnt
Cat is smarter than that
But the house can burn down
You can become homeless
Do you have fire insurance?
[Repeat/mutate]
I think what you're talking about is worry and/or rumination, both of which describe a perseverative and repetitive thinking style (e.g., Watkins, 2008).  Worry is future-oriented whereas rumination is past-oriented. We don't understand the mechanisms all that well at the level of analysis you're interested in, but I'll present some brain-level theories/data about these processes.

Rumination

Rumination is associated with functional hyperconnectivity between the default mode network (DMN) and subgenual prefrontal cortex (sgPFC), which may be mediated by connections with the medial dorsal thalamus (Hamilton, Farmer, Fogelman, &amp; Gotlib, 2015). The DMN is involved with affective self-referential thought and the sgPFC supports affective behavioral withdrawal.  Together, the DMN and sgPFC might produce a ruminative state that is "self-focused, valenced, and withdrawn" (Hamilton et al., 2015, p. 227).  Other analyses also reveal structural and resting state abnormalities associated with rumination, involving areas related to cognitive control (Kuhn, Vanderhasselt, de Raedt, &amp; Gallinat, 2012).  Rumination and cognitive control deficits (e.g., in working memory; Joormann, Levens, &amp; Gotlib, 2011) are strongly related, explaining why trait ruminators have difficulties with disengaging from their repetitive, intrusive thoughts.

Worry

Worry seems to be associated with increased activation of anterior cingulate and dorsal medial prefrontal cortex, involved with mentalizing and self-reflection.  And pathological worry (in GAD) may be associated with prolonged activation of these areas, possibly representing difficulties inhibiting worrying thoughts (Paulesu et al., 2010).  Hyperanxious individuals also tend to show greater amygdala and insula activity to emotional stimuli (Etkin &amp; Wager, 2007).  This may indicate that pathological worry arises from dysfunctional salience processing ("Is this stimulus biologically relevant to me?") and emotional processing/reactivity.