Why is masturbation not allowed while intercourse without the purpose of offspring is allowed in RCC? The catechism of the RCC state that masturbation isn't appropriate and is immoral. But within a marriage a man can penetrate his wife, when the woman hasn't her fertile period. But why does the RCC makes this distinction, while in both cases there is actually (specially for the man) just a purpose of lust.
It is because of what you actually are doing.  When performing the marital act (as the good Catholic books call it) within marriage, you're not doing anything to prevent conception, you're just using the normal human cycles to pick a time to make love when the odds of conceiving a child are near zero.

Masturbation, even between partners, prevents conception like other forms of birth control.  

This is covered in 50 Questions for the natural law. Where Dr. Charles Rice says mutual masturbation "treats the other person as an object." And he applies the title of mutual masturbation to all forms of contraceptive sex.  

Natural Family Planning requires communication between the spouses about what they're actually doing.  So, even when it's outside the fertile period, you're still communicating about whether or not your act is likely to produce a child.  So it's still focused on the procreative aspect of marital relations.  

Beyond that, it's better this way, according to Pope Paul in Humanæ Vitæ:


  The right and lawful ordering of birth demands, first of all, that spouses fully recognize and value the true blessings of family life and that they acquire complete mastery over themselves and their emotions.  For if with the aid of reason and of free will they are to control their natural drives, there can be no doubt at all of the need for self-denial. Only then will the expression of love, essential to married life, conform to right order.  This is especially clear in the practice of periodic continence. Self-discipline of this kind is a shining witness to the chastity of husband and wife and, far from being a hindrance to their love of one another, transforms it by giving it a more truly human character. And if this self-discipline does demand that they persevere in their purpose and efforts, it has at the same time the salutary effect of enabling husband and wife to develop to their personalities and to be enriched with spiritual blessings. For it brings to family life abundant fruits of tranquility and peace. It helps in solving difficulties of other kinds. It fosters in husband and wife thoughtfulness and loving consideration for one another. It helps them to repel inordinate self-love, which is the opposite of charity. It arouses in them a consciousness of their responsibilities. And finally, it confers upon parents a deeper and more effective influence in the education of their children. As their children grow up, they develop a right sense of values and achieve a serene and harmonious use of their mental and physical powers.  


So much of what the Church teaches is regarded as merely a "ban on X" but what She's really trying to get at is an "Affirmation of Y which requires an exclusion of X".