Why do I sometimes wake up with bites in my mouth that seemingly come out of nowhere and sometimes they turn into ulcers and are very annoying?

Quite common. The tongue or cheek biting during sleep has been reported as a common symptom in association with night bruxism. The custom night guard can be designed and fabricated by your dentist to prevent jaw closings during sleep, therefore preventing tongue injury.
Might be.... 1) trauma from biting your cheeks in your sleep. If it is in a straight line along your cheek from the front to the back of your mouth, than this us a good possibility. 2) Chron's Disease- if these areas are popping up all over your mouth, not just in areas you can accidentally bite, than this is a real possibility and you should be evaluated by a Gastroenerologist.
Where are they? Are the bites on your tongue? On your lips? The insides of your cheeks? We need more information. What do the bites look like? Do they hurt? How long do they last?