Trees naturally pull in carbon (and water) from the atmosphere to feed themselves. It’s just a happy coincidence that, in doing so, that process produces oxygen, which is a necessity for lives to thrive.
The crucial takeaway is that trees absorb carbon and one of the biggest aspects of global warming is the rising amount of carbon dioxide trapped in our atmosphere.
Carbon dioxide is one of several greenhouse gases contributing to our rapid climate change. Since trees already absorb carbon, we need to plant even more to combat the effect it’s having on our planet.