hat on baby?

Do you put a hat on your baby at night when sleeping? I normally did this since she was born but the midwife advised it's not safe?