Review of 1,039 studies indicates exercise can be more effective than counselling or medication for depression

I think there are multiple components to this.

One, making incremental, observable progress in something definitely influences dopamine production. Seeing the weight number go up on your lifts, or your run time improving, etc, is bound to induce a feeling of satisfaction and progress that might otherwise be missing from your life. Having had severe bouts of depression myself, some of my worst lows were during times when I felt like I had nothing to build or work toward, no goals, no progress. Not even small ones. The small wins you find in exercise can make a world of difference.

Second, many kinds of exercise also reduce social isolation, which is a major depression driver. Whether it's a yoga class, running group, martial arts gym, etc, being in an environment that puts you in close proximity with like-minded peers adds an element of community and social gratification that again, may otherwise be missing from your life and contributing to your depression. I think many people who turn to exercise to combat depression and came away feeling dissatisfied likely tried lifting weights, which is a highly solitary form of exercise.

Third, just recognizing that you are making a positive improvement to your body can help build or improve self esteem. Looking better in your clothes or getting compliments can do a lot to improve your self image and confidence.

While exercise isn't a replacement for therapy or medication, it goes an extremely long way in building healthy lifestyle habits and improving various aspects of your life that may be driving depressive feelings. I started going to the gym about a year ago, and while the literal exercise has done a lot for me, it's the adjacent stuff (social exposure, community, reaching goals) that made the most profound impact on my depression.

/r/science Thread Link - psypost.org