In terms of ecology and evolution, it makes perfect sense that a signal should be available to tell an animal when threats to its health and survival are evident. Such a signal should be very clear amidst the cacophony of signals presented to the nervous system, and should organize behaviors with some prejudice in order to reduce harm. If it hurts, get away from it.
In simpler animals with small numbers of neurons, such signals activate behaviors through reflex actions that are tuned to escape or defend against harm.
In larger-brained animals, things get considerably more complicated. Many have argued that the major reason for having a large and metabolically expensive brain is to learn rapidly changing things about the way the current environment works that evolution wouldn't have time to program. Perhaps the most important of these is the changing landscape of behaviors and attitudes of other intelligent creatures, with whom we must negotiate for our own health and survival.
As a result, large-brained animals like humans have to deal with a wide array of things that we come to like or dislike through conditioning. Our pleasure and pain signals can be trained onto new stimuli, as Ivan Pavlov famously demonstrated. Our genes haven't had enough time to learn to tell us that pursuing a graduate degree or avoiding aggressively-marketed junk foods will benefit us. Rather, our big brains each may learn to act as an internal 'marketplace' for competing ideas, urges, interests, and values, many of which are the products of the time and place in which we live.
We do know that, in humans, excessive suffering and stress can lead to chronic anxiety, depression, chemical dependence, ulcers, neuronal death, cardiovascular disease, immunosuppression, abuse of others, and suicide.
Suffering can guide us toward success and away from harm, or it can simply harm us. Knowing the difference is a judgment that perhaps only humans are equipped to make, although many do not.