I guess the simplest explanation is because your mind isn't connected to your body, which is feeling the headache. That's happened to me too, a few times. I used to get bad migraines and when I dreamt, they'd always vanish.