Babies have a relatively large head
to body ratio and can lose a large amount of body heat to their surroundings.
Body heat requires energy & to grow babies need to put the energy they have into growth rather than trying to stay warm. Hats help cut the energy losses & certainly should be warn when they are in cold surroundings at any age. Indoors, it is less of an issue.