One of the functions of a cough is to remove mucus from our airways. Unfortunately, once we're lying down, it makes it more likely that mucus will begin to collect in the back of the throat, meaning that we cough to clear the blockage.
This is a companion discussion topic for the original article at https://patient.info/news-and-features/why-your-cough-gets-worse-at-night