A Confession is invalid when the penitent knowingly conceals a mortal sin in his or her life.
If you are consciously aware of a mortal sin and for some reason choose not to confess, you make a mockery of the sacrament; this is sacrilege.
Article 2120 of the Catechism of the Catholic Church defines sacrilege in this fashion: “…consists in profaning or treating unworthily the sacraments and other liturgical actions, as well as persons, things, or places consecrated to God.”
Therefore, knowingly withholding a mortal sin from the priest in Confession, the penitent is making a sham of the sacrament. Sacrilege is a grievous sin, and a person shouldn’t receive Holy Communion until it is rectified in Confession, otherwise that Communion received would be a further sacrilege.
A Confession is also considered invalid when the penitent has no intention of revising his life and will continue the same sin.