Sacraments can be denied or postponed for different reasons.
The most drastic is called excommunication. It is the penal exclusion of a baptized faithful from the community of faith. There are two ways excommunication can occur: non-declared (automatically) or declared (judicial process or administrative decree). Automatic excommunication is the most common.
A famous declared excommunication took place in 1953 when the Vatican punished a Boston priest, Father Leonard Feeney, for his refusal to recant a distorted teaching on the principle of extra ecclesia nulla salus (outside the church there is no salvation). He erroneously and publicly maintained that only Catholic Christians could go to heaven and that Protestants would go to hell unless they converted to Catholicism.
The 1983 Code of Canon Law lists seven reasons for automatic excommunication: apostasy, heresy, schism, desecration of the Holy Eucharist, laying violent hands on the pope, absolution of an accomplice in the sin against the sixth commandment, episcopal consecration without approval and authorization from the pope, violation of the seal of confession by a priest-confessor, and procuring a direct abortion. The excommunicated are barred from receiving the sacraments and sacramentals, and are therefore deprived of receiving sacramental grace.
A person who remains in the state of mortal sin should not receive the sacrament of the Holy Eucharist until he or she receives absolution in the sacrament of penance. Along this line, if the person is in a persistent state such as an invalid marriage, it is the obligation of that person to have his or her marriage rectified in the Church, and until then should also refrain from receiving Holy Communion. A notoriously sinful person, such as a known criminal who is unrepentant or one whose sin is common knowledge and would cause scandal to the faithful, can be barred as well. It was common for members of the Mafia not to be permitted to be buried in a Catholic cemetery.
A person can also be denied the sacraments for a more benign reason. For example, a person who is baptized but not in full communion with the Catholic Church is not permitted to receive the Holy Eucharist. One must be in communion in order to receive Communion; in other words, they must be united and in agreement with all the doctrines, disciplines and authority of the church or religion which is offering the Communion.
Communion implies union of mind and belief as well as union of church. The word itself comes from two Latin words, “cum” (with) + “unio” (united). Communio in Latin means to be “united with” or to be in agreement. Catholic understanding of the Holy Eucharist and Protestant understanding is quite different. At this point in time there is no inter-communion between Catholics and Protestants. Often at Catholic weddings the celebrants will invite people to read the guidelines for Holy Communion in the back of the missalette, or in the back of a wedding program, to educate them regarding who can receive the Blessed Sacrament.
The sacraments of Penance, Holy Eucharist and Anointing of the Sick can be administered to members of Eastern Orthodox Churches not in full communion with the Catholic Church, if they spontaneously ask for them and are properly disposed. The same applies to members of other Churches which have all seven valid Sacraments, like the Polish National Catholic Church in the USA and Canada.
Finally, a Catholic in confession who is not ready to give up the sin, confess, and make amends might be deterred from receiving absolution until a time when the penitent is ready to make the firm purpose of change.