i have a trek 69er ss, used to drop the chain at the back quite painfully from (i’m pretty sure now) frame flex – i put a couple big cogs from an old cassette spaced either side of the main one, it’s never come off since. bit of a weird solution but did notice that they originally came with something to keep it on..
i also sometimes have the back end coming off the road when sprinting up hills on a road bike incidentally, just too far over the front – i don’t know if the two are related though!