I hate to act like a nerd but I learned the reason for this recently
It’s a pretty similar reason to what was described here but, since we don’t know what dying is like, dying in a dream causes stress and stress causes you to wake up
But at the same time, how can you do research on something that happens in your brain. So we are very certain that that is how it works, but it might not be.
(Sorry if I'm sounding like a jerk, I just like pointing out possibilities.)