Bad breath is the end result of bacteria working away on the food stuck between your teeth. Regular brushing and flossing will most commonly solve this problem. The flossing is important because the back teeth get a lot of food stuck between them and brushing alone will not remove it.
Many people sleep with their mouth open which allows more bacteria to get in there and work away at the food between your teeth. You’re also not swallowing as much, if at all, while you’re sleeping. This also helps the bacteria grow, and they will grow pretty quickly.
Of course the possibility also exists that a goat, possibly a ghost goat, is sneaking into your room while you sleep and rubbing his ass in your mouth, this possibility is quite unlikely; however, if you know your mouth smells like goat’s ass specifically it a theory we must identify.