A cough is a reflex that occurs when something is irritating your baby's airways. Mucus is a common irritant.
Babies are apt to get the occasional cough due to something like
the common cold
croup
bronchiolitis
food or drink “going down the wrong way.”