The Buddha taught the middle way, neither harsh self-punishment nor loose indulgence, and monastic celibacy was framed within that same balance
The same sermon that introduces the Eightfold Path explicitly rejects the self-punishing asceticism the Buddha had personally tried and abandoned before his awakening.
The Dhammacakkappavattana Sutta records the Buddha's first teaching after his awakening, delivered to five former companions at the Deer Park in Sarnath. He opens by naming two extremes for a renunciant to avoid: devotion to sensual pleasure, which he calls low and unprofitable, and devotion to self-mortification, which he calls painful and equally unprofitable — a pointed statement, since the Buddha had personally practiced extreme asceticism for years before concluding it did not lead to awakening. Between these he places the middle way, elaborated in this same sutta as the Noble Eightfold Path. Monastic celibacy in the tradition that follows is meant to sit inside this framework: renunciation of sexual activity is not framed as an act of self-punishment or bodily hostility, which the sutta explicitly rejects, but as one part of a disciplined, moderate life aimed at reducing craving without treating the body as an enemy.
Dhammacakkappavattana Sutta