In general, there are two common reasons why birds evolve flightlessness. When birds land on an island where there aren't predators (including mammals) that would hunt them or steal their eggs, they sometimes settle there and gradually adapt to living on the ground.
Since they don't experience evolutionary pressure to stay in flying form, they gradually lose some of the features of their skeletons and feathers that help them fly. Meanwhile, some birds' bodies change when they evolve semi-aquatic lifestyles. Penguins, for instance, can't fly, but they swim in a way that's akin to "flying underwater." Their feathers and skeletons have changed accordingly.