Pain is biologically advantageous but only up to a point. The skin->spinal cord->muscle reflex arc protects us from hot stoves and sharp objects, internal pain is symptomatic of injury or disease, and mental suffering may indicate that a change in lifestyle is needed.
But of what use is that pain that comes from vain ambition, fear of mortality, desire for limitless wealth, and terror in conceptualizing the gods? The irony of his position is that his argument is consequentialist. 'Pain is useful, therefore pain cannot be bad'.
Thought experiment; as it is, computers throw error messages when something goes wrong. If we could design a computer that feels pain and screams when something goes wrong, would that be an ethically neutral decision? No; pain is bad.