There is as yet no good explanation for this. Like mammals, birds have cycles of NREM and REM sleep, but with some differences. Also, most birds do not lose muscle tone during REM sleep as consistently as mammals do, which is understandable, since many birds sleep while standing or perching. Some birds, such as pheasants and partridges, sleep on the ground. Water fowl can sleep while swimming.
Some parrots sleep hanging down.
It is suspected that some birds sleep aloft during long transoceanic flights. Once again, the importance of sleep in the animal kingdom is underscored by the amazing number of accommodations and circumstances during which it occurs. It has been identified in alligators, turtles, lizards, frogs, salamanders, bees, wasps, flies, dragon flies, grasshoppers, butterflies, scorpions, the primitive invertebrate sea hare and even, according to one unsubstantiated report, in adolescent turtles of the mutant ninja variety. We cannot yet conclude, however, that sleep in all these animals reflects the same physiological processes and fulfills the same functional goals as the sleep of mammals and birds. Because mammals and birds have similar EEG, EOG and EMG activity when they sleep, we have some confidence that their similar sleep behaviors are produced by similar physiological processes.