Ever heard of "in through the nose, out through the mouth?"
That's how people typically breathe when they're at rest.
Your nasal passages moisten the air before it enters your lungs, filtering out any debris or environmental irritants.
But when you exercise, you breathe much faster than normal. During an intense workout, people tend to breathe through their mouths to process larger volumes of oxygen.
When they do, the dry air hits their lungs head-on, carrying with it any irritants or particles from the air. The resulting irritation is what causes coughing and phlegm build-up. Coughing produces mucus, which protects the lungs from foreign substances.