Recently I heard a tragic story of a couple whose baby was stillborn. The couple requested that their stillborn baby be baptized, and the priest had to gently deny their request. Some people hear this and are shocked, dismayed, and even angered: "Why won't he baptize their baby? They're in pain and anguish, and he won't even grant this simple request. Isn't the Church supposed to help people in times like this?" What is the answer?
The Church would not baptize a stillborn baby or any other deceased person because it cannot. That is, you could go through the motions of baptism, but no baptism would happen. Why not? Because the sacraments are for the living. What does that mean? And why is that the case?
A human person is a composite of body and soul, not as two separate "things" connected by some metaphysical glue, but rather as two principles that together make a whole--it is an embodied soul and an animated body. The human person is alive when the body and soul are united, and dead when they are separated. In the dead person, the link between the body and soul has been severed for a time. Your consciousness, seated in your seal, does not feel the pain of your pinched arm when you're dead.
Now let's consider the sacraments. Much like a person, sacraments are a composite of two principles: a physical sign and a spiritual reality conveyed by the sign. In baptism, we have the physical sign of the washing of water and the spiritual reality of the cleansing from sin, the dying to self (as by drowning) and being born again in Christ (through "water and the Spirit," like coming forth from a spiritual womb). The physical sign is applied to the body, and the spiritual effect affects the soul (as well as the body). BUT if the soul is no longer joined to the body, i.e. if the person is dead, then, just as a disembodied soul can't feel the pain of a pinched arm, so a disembodied soul can't receive the spiritual effect of a baptized head. The link between body and soul has been broken, and thus the sacraments cannot be applied. This is why the sacraments are for the living, for those in the "wayfaring state": only to them can they be applied.
Some will ask, "How do we know when the soul has left the body? Maybe when a person appears to be physically dead, the soul is still there for a time." The soul is what gives life to the body--if there is no life in the body, there is no soul in the body. If you have no good reason to think someone is alive, you shouldn't assume they are. We don't leave cadavers unburied "just in case they wake up." And we don't give the sacraments to corpses, just in case they might still be somehow alive without us noticing.
Now, the parents of that stillborn baby are in what may well be the most terrible moment of their lives, and I can understand them seeking some comfort for themselves and their deceased child. And the Church should give them all the comfort it can. But it shouldn't give them the comfort it can't. The priest should, at the proper time, explain to the parents that there's no need for baptism at this point, that their child is already in God's loving hands, and that we can trust in His mercy. In the end, that is all any of us can do.