How can a nighttime cough medication be both a cough suppressant and an expectorant?

In the lungs nothing. Between the lungs (in the "mediastinum") there is a proliferation of scar tissue that can lead to coonstriction of the large central vessels and airways leading into the lung. The cause is often blamed on a fungal infection, but in some people the cause is unknown.
Check the label. "nighttime cough medicine" often hs more than 1 medication in it. Read the whole label and you may find that there is a med that dries up mucus to consolidate it and another that decreases the frequency of cough. They seem to work against each other but, they tag-team so that you can cough efficiently...Then sleep!