Praying bareheaded is legally disliked if done out of laziness, but acceptable if done out of genuine humility and self-abasement.

Disliked Acts in Prayer Part 2: Environmental and Posture Dislikes