With millions of years of evolution behind our species, and a billion behind life in general, we might expect - in a Panglossian frame of mind - to function very well, and to be free from unnecessary misery. Wouldn't the ruthless process of selection have removed causes for fitness-draining suffering and poor well-being in general?
There are two main reasons why we should expect a great deal of unnecessary suffering to be the product of evolution.
1. Adaptation Executors
A maxim of evolutionary biology is that organisms (like us) are adaptation executors, not fitness maximizers. Evolutionary processes create organisms that execute biologically-mediated strategies - it does not create rational beings that maximize fitness in all instances.
In many cases, the detection mechanism is "too sensitive" for our own good - our pain response and our startle response, for example, both generate lots of "false positives" in terms of fitness threats we may respond productively to. This is because in the environment of evolutionary adaptedness, the cost of tons of false positives was outweighed by the benefit of being "right" that one time that counts.
Our social ostracism detection system has also been posited to be hypersensitive, for the above evolutionary reasons. Social belonging has such a high survival value that any potential threat must be addressed immediately. This is true even if it means 100 "false positives" - instances of social ostracism with no actual fitness threat - must be suffered by the individual organism.
What's a good idea for evolution is not necessarily a good idea for you. Evolution works fine - it just doesn't give a fuck about the well-being of individual organisms.
In other cases, complex systems interact in such a way that the detection system is "broken." This may be because the EEA doesn't match current conditions, as may be the case with asthma, allergies, diabetes, and obesity. In other cases, it may be because organisms aren't created perfectly every time, and are not perfectly matched even to EEA conditions. Evolution can only act on the mutations it's given. The pain of a migraine, for instance, is not an indication of a necessary response the way the pain from a burn is. Problems may not reflect any adaptation at all - it might be a defect in the system, or in the organism.
Written in response to this comment by The Plague Doctor.