First of all, unless one dies in unrepentant mortal sins, there is always hope for salvation. Of course, only God (Father, Son, and Holy Spirit) know if a person has died in mortal sin - many times, even the person himself/herself often does not know due to self-deception. Even if a person is currently in a state of mortal sin and has committed a sin so egregious that it evokes automatic excommunication (such as heresy, abortion, false ordination, breaking the seal of confession, etc.), there is the possibility for salvation if that person repents and confesses the sin (though some of these sins require a bishop or the See of Peter to give absolution).
St. Paul mentions this himself when he gives the first known excommunication order in his first letter to the Corinthians. One of the members of the church in Corinth was in an incestuous marriage with his step-mother (cf. 1 Cor 5:1-4a). Paul tells the church, “When you have gathered together and I am with you in spirit and the power of [our] Lord Jesus, you are to deliver this man to Satan for the destruction of his flesh, so that his spirit may be saved on the day of the Lord” (1 Cor 5:4b-5, NAB). As such, St. Paul is prescribing excommunication as a medicinal remedy. He is pretty much saying that cutting this person off from the community of believers and the sacraments for a time may be the only thing that can convince this man to repent of his sins.