The church has historically viewed sexuality as having been designed for procreation. In recent decades, the role that sexual behavior plays in strengthening the marriage bond has been acknowledged. Still, sexual acts that cannot lead to conception are condemned as being against natural law.
Pope Paul VI issued a declaration in 1975 on many aspects of human sexuality. It is titled: "Persona Humana - Declaration on Certain Questions Concerning Sexual Ethics." Priests and other officials in the Roman Catholic church are not allowed to offer alternative opinions in public, and even in private should not give their own opinion but the opinion and teaching of the church.
Some of the pope's comments in "Persona Humana" apply to masturbation:
"...masturbation constitutes a grave moral disorder..."
"...masturbation is an intrinsically and seriously disordered act...the deliberate use of the sexual faculty outside normal conjugal relations essentially contradicts the finality of the faculty. For it lacks the sexual relationship called for by the moral order, namely the relationship which realizes 'the full sense of mutual self-giving and human procreation in the context of true love.' All deliberate exercise of sexuality must be reserved to this regular relationship."
"Even if it cannot be proved that Scripture condemns this sin by name, the tradition of the Church has rightly understood it to be condemned in the New Testament when the latter speaks of 'impurity,' 'unchasteness' and other vices contrary to chastity and continence."
"The frequency of the phenomenon in question is certainly to be linked with man's innate weakness following original sin; but it is also to be linked with the loss of a sense of God, with the corruption of morals engendered by the commercialization of vice, with the unrestrained licentiousness of so many public entertainments and publications, as well as with the neglect of modesty, which is the guardian of chastity."
Church Catechism:
The Catechism of the Catholic Church (CCC) discusses masturbation in its section "Offenses against chastity:"
2351: Lust is disordered desire for or inordinate enjoyment of sexual pleasure. Sexual pleasure is morally disordered when sought for itself, isolated from its procreative and unitive purposes.
2352: By masturbation is to be understood the deliberate stimulation of the genital organs in order to derive sexual pleasure. 'Both the Magisterium of the Church, in the course of a constant tradition, and the moral sense of the faithful have been in no doubt and have firmly maintained that masturbation is an intrinsically and gravely disordered action.' 'The deliberate use of the sexual faculty, for whatever reason, outside of marriage is essentially contrary to its purpose.' For here sexual pleasure is sought outside of 'the sexual relationship which is demanded by the moral order and in which the total meaning of mutual self-giving and human procreation in the context of true love is achieved'."
"To form an equitable judgment about the subjects' moral responsibility and to guide pastoral action, one must take into account the affective immaturity, force of acquired habit, conditions of anxiety or other psychological or social factors that lessen, if not even reduce to a minimum, moral culpability."