The head size of babies are proportinately bigger than their body size. As a result of which a lot of heat transfer could happen. Such heat fluctuations may cause the baby to fall sick.
Therefore, to prevent such heat trasfer & to keep the body temperature normal, babies are required to wear a hat. Moreover, a hat could protect the baby from sunlight or cold chills of outside. But it is not necessary inside your house, as the room temperature doesnt have such extremities.