Good editors really can add value, in two ways.
First, editors are industry professionals who can educate often-naive authors about the facts of life in the real world of publishing. (Agents are great at this too, often even better.) The other answers have some excellent details on this, but I think it boils down to: Just because you want to write it doesn’t mean somebody else wants to read it, and certainly not that he or she wants to pay for it.
Second, and even more important, editors can view writers and their products from the outside, which authors themselves rarely can. Think of Burns’ “wad some Pow’r the giftie gie us, to see oursels as ithers see us”–that’s the power editors have and writers usually don’t.
A lot of times, though, it means being able to see the chaff as well as the wheat, the haystack as well as the needle, and finding a way to tell authors infatuated with the sound of their own voices or opinions that the piece would be better if pruned back, rearranged, rewritten, etc. Or, unfortunately, sometimes just dropped entirely, with the writer moving on to a more promising project.
Bottom line, editors serve as proxies for readers at large–proxies who, if they are doing their job properly, not only understand what those readers need and appreciate, but are able to help writers do what is necessary to reach them. Readers are outer-directed, writers are often inner-directed, editors try to bridge the gap between the two so their interactions can be more mutually rewarding. (Spoiler alert: that usually means asking why anybody other than the writer should care about something, cutting verbiage, tightening language, getting to the point, all the usual stuff.)