Sometimes it's not the content of a thought that is the problem, but the way a thought affects other thoughts. In other words, often the goal of controlling your perception of your train-of-thought, is to use the feedback mechanism of quieting and negatively-training ignored thoughts, to prevent and discourage your thoughts from spiralling (as in panic disorder) or to prevent thoughts detached from a referent (as in schizophrenia) or to prevent thoughts from over-staying their usefulness (as in OCD.) In each of these syndromes, the analyzing-agent is freaking out due to something, and the perception of the freak-out is painful for the perceiving-agent, just like having someone shout into your ear is painful.
As well, in some psychological paradigms that people tend to intuitively use (at least in Western culture), some thoughts that diverge greatly from the "motivational base" of other thoughts—thoughts that aren't coherent with the rest of the self—are deemed to be "intrusive" or "ego-dystonic." (This doesn't make as much sense when you model your self as containing multiple agents with distinct preferences, as in the Internal Family Systems model, but I digress.) In such cases, mindfulness meditation can be used as a tool to silence incoherent thoughts, since they often trigger a crisis of self whenever they occur (e.g. "I keep thinking about what would happen if I stabbed people; does that mean I want to stab people?" or "I keep thinking about stepping out into traffic; does that mean I want to die?" when often these are just the ramblings of an internal agent obsessed with not doing those things who really wants to make sure you're aware that the consequences would be bad if you did do them.)
In either case, there's nothing wrong with thinking certain thoughts. It's really just that your analyzing-agent thinks there's something wrong with those thoughts that it is thinking, and this makes it do very useless and annoying things (from the perspective of the perceiving agent), like repeating the same thought over and over, or being unable to focus on or interpret what's in front of it, etc. These are "bad" inputs to thought-perception, just like clashing, atonal noise is "bad" input to sound-perception. (It's really the thinking agent that notices that the perceiving agent is experiencing pain qualia due to its output, and who then decides to do something about it by modulating the perceiving agent such that the thinking agent gets less CPU-time to run. Other than autonomic stuff like breathing and hardware-accelerated stuff like forming phoenemes with the mouth, it's only the thinking agent that ever "does" anything at all. But it's helpful to model the things it does because of the preferences of other agents, as being done by those other agents.)
As well, in some psychological paradigms that people tend to intuitively use (at least in Western culture), some thoughts that diverge greatly from the "motivational base" of other thoughts—thoughts that aren't coherent with the rest of the self—are deemed to be "intrusive" or "ego-dystonic." (This doesn't make as much sense when you model your self as containing multiple agents with distinct preferences, as in the Internal Family Systems model, but I digress.) In such cases, mindfulness meditation can be used as a tool to silence incoherent thoughts, since they often trigger a crisis of self whenever they occur (e.g. "I keep thinking about what would happen if I stabbed people; does that mean I want to stab people?" or "I keep thinking about stepping out into traffic; does that mean I want to die?" when often these are just the ramblings of an internal agent obsessed with not doing those things who really wants to make sure you're aware that the consequences would be bad if you did do them.)
In either case, there's nothing wrong with thinking certain thoughts. It's really just that your analyzing-agent thinks there's something wrong with those thoughts that it is thinking, and this makes it do very useless and annoying things (from the perspective of the perceiving agent), like repeating the same thought over and over, or being unable to focus on or interpret what's in front of it, etc. These are "bad" inputs to thought-perception, just like clashing, atonal noise is "bad" input to sound-perception. (It's really the thinking agent that notices that the perceiving agent is experiencing pain qualia due to its output, and who then decides to do something about it by modulating the perceiving agent such that the thinking agent gets less CPU-time to run. Other than autonomic stuff like breathing and hardware-accelerated stuff like forming phoenemes with the mouth, it's only the thinking agent that ever "does" anything at all. But it's helpful to model the things it does because of the preferences of other agents, as being done by those other agents.)