Teeth grinding usually occurs during your deepest sleep, which can occur just prior to waking, if you’re rest deprived or over-tired. That action can cause the headache. But, I think a lot of the time it’s just grogginess of the mind trying to pull out of the deep snooze and accept the pull of gravity and extra oxygen flow.