When toxic substances are inhaled, they can irritate the respiratory tract, leading to an inflammatory response. This irritation stimulates cough receptors in the airways, resulting in a cough. The body's immune response may also produce mucus to trap and expel the irritants.