To wear a cap is the symbol of Muslims, it is not necessary to wear it every time; one can take it off when he needs, as while going to bed. She can uncover her head if there is no chance of a non-mahram having a look at her hair. This is the ruling while going to sleep, covering head before mahram is not necessary.
Allah (Subhana Wa Ta’ala) knows Best
Darul Uloom Deoband