Here is a picture of Curlews stood on one leg to sleep, with their long beaks tucked under their wings. I took the photograph on the Threave Estate. Birds have blood supplies down their legs and into their beaks. Where blood flows close to the skin, conduction will take thermal energy out to the surface where is dissipated by heat radiation and convection. The main body of the bird is covered with feathers. Air is trapped in small pockets between the feathers. Air is a poor conductor of heat because the particles in air are far apart and not joined. However air is good at convection. The small pockets of air mean that convection cannot get going. So Curlews tuck one leg and their beak into their feathers so that these parts of the body benefit from the insulation of the feathers when they sleep. The behaviour must have become widespread because of Natural Selection. Those that didn't got cold and died younger. Those that did tuck their leg and beak in lived longer, bred more often and passed their genes onto their offspring.