Why is (was) it customary for ladies to continue to wear their hats when making a formal visit to someone at home, although they would remove coat, gloves etc?
Hats are worn less now, but at the turn of the 20th century, all adults wore hats whenever they left the house. It was a matter of good personal hygiene, since hats were a protection from industrial dirt.
Men's hats are easily removed, but women's hats with ribbons, bows, flowers and other decorations could be quite an effort to remove, especially if they were anchored with hatpins. Women might also risk messing up their hairdos if they had to remove their hats.