Suffering is likely something that evolved due to it being beneficial for the survival of our species. Suffering is what can help to keep you out of harm's way and can help to motivate you to do things that would be beneficial in increasing your chances of survival. For example, the suffering and discomfort that hunger can cause may motivate you to seek out something to eat. Along either that, seeing others suffer can also help us better avoid things that may come in the way of our survival and reproductive success. For example, if someone becomes horribly sick after eating some berries, seeing them in that awful state might influence us to avoid those berries in the future.
Suffering in some animals, especially in humans, can also be said to play an important role in deepening our bonds with one another, which would have been beneficial when it comes to survival and reproductive success. Shared hardships force us to work together and rely on one another. Furthermore, affective empathy likely requires suffering to work. This is because when we encounter the suffering of someone else, we experience emotion-sharing, leading us to also suffer. This causes us to then become motivated to help the other pein order toer to reduce our suffering.
Basically, suffering is likely just something that we and other organisms evolved to experience because it is a darn useful trait to have. It probably doesn't serve any purpose deeper than that.