Catechism of the Catholic Church
2336 Jesus came to restore creation to the purity of its origins. In the Sermon on the Mount, he interprets God's plan strictly: "You have heard that it was said, 'You shall not commit adultery.' But I say to you that every one who looks at a woman lustfully has already committed adultery with her in his heart."123 What God has joined together, let not man put asunder.124
The tradition of the Church has understood the sixth commandment as encompassing the whole of human sexuality.
II. THE VOCATION TO CHASTITY
2337 Chastity means the successful integration of sexuality within the person and thus the inner unity of man in his bodily and spiritual being. Sexuality, in which man's belonging to the bodily and biological world is expressed, becomes personal and truly human when it is integrated into the relationship of one person to another, in the complete and lifelong mutual gift of a man and a woman. The virtue of chastity therefore involves the integrity of the person and the integrality of the gift.
...
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.
...
2396 Among the sins gravely contrary to chastity are masturbation, fornication, pornography, and homosexual practices.