The error is thinking everything has a "point" or "purpose". That error comes from the ancient human habit of thinking everything in life is part of a plan designed by a guy/guys up there.
There is no point. There is a biological reason for pain, as it has been already explained here, but there is not really a point if you try to rationalize it.
Here we enter my favorite philosophical question.
What is the point of all this?
I think Nietzsche was right when he said about earlier philosophers:
"Regarding life, the wisest men of all ages have judged alike: it is worthless."
Nietzsche was not fooled by that to think that life cannot be given meaning in the form of a lie. After all lie is the nature of purpose since all meaning is a lie. And if we are to have purpose we must lie.
In his words "the lie is a condition of life."