Praise be to Allaah.
If the pilgrim is female, then it is well known that it is permissible for her to cover her head. But if the pilgrim is a man, that is not permissible when he is sleeping or when he is awake. But if he covers it (unintentionally) whilst he is asleep, when he wakes up he must uncover his head, and he does not have to do anything else, because the Pen is lifted from the one who is asleep. End quote.
Majmoo’ Fataawa Ibn ‘Uthaymeen, 22/128.