How is it that some flies are wingless like the sheep ked and the New Zealand bat fly?
What a neat question...someone, ( you) is really thinking!!!!!
As a general rule in evolution, if something is not needed, it tends to not continue forever in a species.
Lots of examples.... flightless birds in New Zealand. Seeeeeee, wings take lots of calories to operate, chest muscles that use lots of energy, and there are dangers to wings, even when they are useful.
Grebes in the Galapagos Islands still have wings, but they cannot fly with them. (Google "Galapagos Grebes" They are used a bit under the water chasing food. But now Galapagos island grebes have webbed feet...better for swimming. In time, These wings would have disappeared. Animals and plants do not keep "expensive items", "just in case"..... Evolution favors the most efficient way for an animal to get its food, and for grebes, whose ancestors came from S. America, wings were in the way. There were no predators in the Galapagos islands until just a few centuries ago.... humans imported cats, rats, which nothing had to deal with ever there, until just, as I said, a few centuries ago. That's millions and millions of years of evolution on the Galapagos Islands with no cats, rats and other things to eat them or their eggs.
There is a huge parrot, a kea in the New Zealand area, that has wings but cannot fly. He is just too heavy. Assuming they can stay away from the imported cats, they would go one to lose the wings, just as the Kiwi has. Far more likely however is that the imported cats will in the end, kill them all, unless their wild areas are fenced to prevent cats from getting to them.
Another example..... there are salamanders in dark caves.... they never see any light. Not ever. And they have evolved to not have eyes, just empty sockets where eyes were, and now covered with skin. Eyes are delicate, and easily infected. Since these were not needed, evolution over the generations and generations.....several thousand......eliminated them.
This does not mean that everything not needed gets eliminated in animals, but evolution favors those capable to making it to adulthood to breed. Salamanders with infected eyes, may not live long, and had humans not introduced predators in some of these pristine areas, those animals would be just fine with no wings...grebes, etc.
Now, about your flies.
Wings in all insects are delicate too, and there is an evolutionary advantage, most of the time, to be able to fly. Flight has evolved three separate times in three separate species.... in mammals with the bat, in birds, whose ancestors were the dinosaurs, and with insects of all sorts.
These that you have referred to have found "earning a living" easier without wings. (Ants often are flightless, even tho some in the nest can still fly.... the workers are flightless.)
Bats tend to sleep in the same cave night after night, and close together too for warmth. So a flightless insect need only be able to crawl thru the hair of one bat onto the hair of another. Same with the sheep ked.... sheep are now in huge flocks. Who needs wings? Keds are pure parasites... take blood from the sheep, and give nothing in return. Every sheep is usually very close to another sheep. Ticks, that infect dogs and even humans, used to have wings, but found crawling up on a blade of grass got them just as quickly to a meal than wings could, without being food for a bird. (So, as you can see, having wings isn't always an advantage.)
Evolution is always changing plants and animals. They are called mutations, and if those mutations prove to be an advantage, the animal matures, and passes that mutation on to the next generation..... but mutations can be bad too. Those animals carrying lethal mutations never make it to adulthood, and die before reproducing. But the same mutation will occur again and again, and evolution will not favor it, ever------------unless the environment for that mutation changes.
So what drives evolution? The environment. That's why the bat fly dropped the wings.... the environment of hair, was easy to get around in. Its ancestors had wings, but the bat fly doesn't need them Google this. Ought to be some interesting stuff on bat flies and sheep ked too.
Please feel free to write if you need added information