It's clear that exercise does have an impact on pain levels. This is true for many conditions. The exact way it works isn't clear. Exercise does release natural pain killers in the body. It's possible exercise alters pain you're expecting before you even begin.
Scientists aren't sure how that works either but they are studying various aspects of exercise and diseases, illnesses, and other conditions. It's clear that general exercise benefits the body overall. In time we expect to be able to find out which exercise works best for each problem and apply that to each individual patient. This idea is called prescription exercise.
Some exercise programs are already known. Back problems caused by disc disease can be managed with McKenzie exercises. Osteoporosis is treated with specific weight bearing and weight lifting exercises. Heart disease can be prevented with aerobic exercise. Someday it's expected that we will know what exercise to prescribe for liver disease, thyroid conditions, autoimmune diseases, and so on.