Dear Confused One,
A priest takes a promise of celibacy and therefore is not able to marry. If they go ahead and get married anyway without telling anyone then they will be first suspended from ministry and dismissed from the priesthood if they persist. As a dismissed priest, they cannot function as a priest and are in bad standing with the Church and, like everyone else who gets married outside the Church, they cannot receive the Sacraments until they reconcile with the Church.
If a priest is up front with the Church, stating that they desire to get married, then they ask to be dispensed from the obligations of the priesthood including celibacy. This is commonly known as laicization. This dispensation is a favor rather then a punishment (i.e. dismissal) and they have to get this favor from Rome. Once they have it they live their life as if they were lay people and they can go ahead and:
- get married and
- they are in good standing with the Church, and
- can receive the Sacraments.
In both cases, the man remains a priest. This is not similar to Declarations of Nullity (known as "annulments") whereby the conclusion is that the Marriage was invalid and therefore did not exist. Priesthood is an indelible thing such that his priesthood is forever. Therefore, in both of the cases above, these men would be able to hear the Confession of someone who is dying and that Confession would be completely valid.
I hope this is helpful.