It's sort of a formal/informal distinction based on day/evening.
Formal event, not at home, day: head covered. Informal event, not at home, day: head covered. Formal event, not at home, evening (ball, opera, dinner party): head uncovered. Informal event, not at home, evening (lecture): head covered.
Also, at home, during the day, you'd keep your head covered if you hadn't done your hair yet. So it can be kind of a distinction between morning, afternoon, and evening.
Basically, if you are attending a ball, the opera, or a dinner party, you'll have your hair really fancy and not need a cap. If you are leaving the house for any other reason, cover your head with a cap or bonnet. If you are leaving the house to make afternoon visits to friends, you can take your hat off at their place. Restaurants are weird and I think you'd keep your headgear on during the day (it's a place of business where you are making an informal visit) but not in the evening, as you'd be there for fancy reasons - pre or post theatre, etc.
(working classes at the theatre, however, anything goes. It's hot as hell up there, since heat rises, the ventilation in those upper balconies sucks, and everyone's just trying not to pass out. Men take off their coats, women remove caps and bonnets, and bourgeois who go slumming are frightened that everyone is in a state of undress. Because it's hot up there. So really, depending on your characters and situation, there's some leeway for obvious environmental factors, but that leeway is really only for the working classes, who are rather expected to revert to being animals in the minds of the bourgeoisie. The late 1820s is when women's fashion starts to suck again from the perspective of August: the wider silhouettes in skirts require more petticoats and the diaphanous muslins of the Directoire and Empire don't have enough body to hold the conical shape or the gigot sleeves of the 1830s. So you can wear pads to hold your sleeves into shape, allowing you to wear thinner fabric, but they you have a pad on your arm, so what was the point in the end? The 1850s development of the cage crinoline [hoop skirt] was a wonderful, wonderful thing.)
What kind of literature and what kind of life is the same question. - Tom Stoppard