One of the main reasons is that when you lie down, it is harder for your body to clear your airways.
Mucus can build up in your throat, triggering your body to cough. When you are awake during the day, you move around and swallow frequently, which reduces the nasal drainage. At night when you are less active, nasal congestion can increase.
Dry air in the bedroom is another cause of throat irritation and coughing.
A humidifier may help put moisture in the air, but you have to take care of the unit. If you don't clean it properly, you can recycle germs back into the air you breathe, worsening a cough or a cold or other respiratory infections. Using sterile water in the humidifier can help keep the air clean.