Our brains are the source of EVERY SINGLE physical sensation or physiological process that is experienced in our bodies. Period.
This is a neuroscientific fact, which you can research and confirm. The most obvious example of this fact is the phenomenon known as Phantom Limb Pain. Look that up, and learn how it is that amputees can experience 100% real and accurate pain in a limb that literally no longer exists. The reason is because the pain, (which is typically the same pain associated with the traumatic injury that resulted in amputation) never came from the limb itself, because that's not where pain is generated. Pain signals are created only in the brain.
As long as we have a brain, we can experience pain, or any other sensation, anywhere in the body, even if there is no physiological purpose for it.
Thus, the neuroscientific mechanism of TMS is fully explained. As for the reason WHY our brains choose to do this on a chronic basis, Dr Sarno's emotional distraction theory is our main starting point. Neuroplasticity also comes into play, which is the basis for the newer Pain Reprocessing Therapy.
If you would like to read an even more radical theoretical basis for connecting emotional distress and repression to the major inflammatory diseases, including cancer, check out When The Body Says No, by Gabor Mate MD. Some people find it scary, but I found it profoundly inspiring. Probably because I've had a strong belief in self-healing all of my adult life (that would be 5 decades plus).