Warning: this is gross.
It’s because colonies of bacteria have been growing in your mouth all night.
Bacteria really love the inside of the human body, and your mouth is no exception. Saliva normally keeps things under control by sweeping away bacteria and the food particles they eat. But at night, when you aren’t producing as much saliva, your mouth becomes a prime breeding ground. As the colonies grow, more and more bacteria feast on food particles and dead cells, producing a bunch of different odor-causing compounds as waste products – like one called cadaverine.
So when you say your mouth smells like a corpse in the morning… that’s not really an exaggeration.