In context, John 3:18, is addressed to “a man of the Pharisees, named Nicodemus, a ruler of the Jews,” who said to Jesus, “Rabbi, we know that you are a teacher come from God; for no one can do these signs that you do, unless God is with him.” In other words, the condemnation for not believing in Jesus in John 3:18 is addressed to those who had seen the signs Jesus had performed but refused to follow him because they “loved darkness rather than light, because their deeds were evil.” (John 3:19)
This is similar to the situation in Matthew 11:20-24:
Then he [Jesus] began to upbraid the cities where most of his mighty works had been done, because they did not repent. “Woe to you, Chorazin! woe to you, Bethsaida! for if the mighty works done in you had been done in Tyre and Sidon, they would have repented long ago in sackcloth and ashes. But I tell you, it shall be more tolerable on the day of judgment for Tyre and Sidon than for you. And you, Capernaum, will you be exalted to heaven? You shall be brought down to Hades. For if the mighty works done in you had been done in Sodom, it would have remained until this day. But I tell you that it shall be more tolerable on the day of judgment for the land of Sodom than for you.”
Recognizing that faith in Jesus and faith in his Catholic Church are gifts from God, the Catechism of the Catholic Church says, in paragraphs 846-847:
“[A]ll salvation comes from Christ the Head through the Church which is his Body…[However, those] who, through no fault of their own, do not know the Gospel of Christ or his Church, but who nevertheless seek God with a sincere heart, and, moved by grace, try in their actions to do his will as they know it through the dictates of their conscience - those too may achieve eternal salvation.”
Therefore, generalizing John 3:18, the Catechism of the Catholic Church says:
679. Christ is Lord of eternal life. Full right to pass definitive
judgement on the works and hearts of men belongs to him as redeemer of the
world. He “acquired” this right by his cross. The Father has given “all
judgement to the Son”. Yet the Son did not come to judge, but to save
and to give the life he has in himself. By rejecting grace in this
life, one already judges oneself, receives according to one’s works, and
can even condemn oneself for all eternity by rejecting the Spirit of
love.
…
682. When he comes at the end of time to judge the living and the dead,
the glorious Christ will reveal the secret disposition of hearts and will
render to each man according to his works, and according to his acceptance
or refusal of grace.