The Catechism in Questions & Answers

547. In what way do the departed receive salvation?

Jesus Christ is Lord over both the dead and the living. It is the will of God that all men be saved (cf. 1 Timothy 2: 4-6). This occurs through the sermon, the sacrament, and the forgiveness of sins. Belief in Jesus Christ is indispensable for this. This applies to both the dead and the living alike.
That the gospel must also be preached to the departed is clear from 1 Peter 4: 6: “For this reason the gospel was preached also to those who are dead, that they might be judged according to men in the flesh, but live according to God in the spirit.”

“For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life.”
John 3: 16