
Because your legs are curved and your spine is "S" shaped, flat beds create gaps where your legs and spine are not supported.
It's a physiological fact that muscles in use are in a state of tension. When you are forced to hold your head up, stretch your legs and spine, support your arms and legs, and move your body yourself to change your position (or improvise contoured support with pillows as you must do in a flat bed), your muscles stay in tension. That is why when you lie on your back in a flat bed, you have to constantly move your body to stay comfortable.
Even turning onto your side doesn't help for long, because lying on your side eventually cuts off blood circulation, hampers breathing, and gravity exerts disturbing downward pressure on your internal organs. Thus you turn again, because the flat surface you are sleeping on is actually causing your curved body pain and forcing your muscles to stay in tension.

When asleep, you unconsciously move into one position after another to escape this pain and tension, but since your bed is flat and can't conform to your body's curves, you toss and turn all night long. A good night's sleep is difficult to achieve on a flat bed!