James explains it well.
Jas 2:14-26 What good is it, my brothers, if someone says he has faith but does not have works? Can that faith save him? If a brother or sister is poorly clothed and lacking in daily food, and one of you says to them, “Go in peace, be warmed and filled,” without giving them the things needed for the body, what good is that? So also faith by itself, if it does not have works, is dead. But someone will say, “You have faith and I have works.” Show me your faith apart from your works, and I will show you my faith by my works. You believe that God is one; you do well. Even the demons believe-and shudder! Do you want to be shown, you foolish person, that faith apart from works is useless? Was not Abraham our father justified by works when he offered up his son Isaac on the altar? You see that faith was active along with his works, and faith was completed by his works; and the Scripture was fulfilled that says, “Abraham believed God, and it was counted to him as righteousness”-and he was called a friend of God. You see that a person is justified by works and not by faith alone. And in the same way was not also Rahab the prostitute justified by works when she received the messengers and sent them out by another way? For as the body apart from the spirit is dead, so also faith apart from works is dead.
1John 5:1-5 Everyone who believes that Jesus is the Christ has been born of God, and everyone who loves the Father loves whoever has been born of him. By this we know that we love the children of God, when we love God and obey his commandments. For this is the love of God, that we keep his commandments. And his commandments are not burdensome. For everyone who has been born of God overcomes the world. And this is the victory that has overcome the world-our faith. Who is it that overcomes the world except the one who believes that Jesus is the Son of God?
It is clear from scripture that works alone cannot get you salvation as it is a free gift from Almighty God, but it requires faith and belief in Christ Jesus’s sacrifice along with works.
James notes that faith without works is dead as faith produces good works. If one practices bad works and declares one has faith in God and Christ, then one is a liar and will not receive salvation. So, neither faith alone nor works alone but both are required. It is therefore that one’s works can disqualify one if one is judged by them, as righteous works are produced by those exercising faith, but unrighteous works by those who do not have faith.
1Pet 1:17 And if you call on him as Father who judges impartially according to each one's deeds, conduct yourselves with fear throughout the time of your exile,
Mark 16:16 Whoever believes and is baptized will be saved, but whoever does not believe will be condemned.
1Cor 11:32 But when we are judged by the Lord, we are disciplined so that we may not be condemned along with the world. - CLV
Rev 2:23 And her children shall I be killing with death, and all the ecclesias shall know that I am He Who is searching the kidneys and hearts. And I will be giving to each of you in accord with your acts.
Matthew 16:27 For the Son of Man will come in His Father's glory with His angels, and then He will repay each one according to what he has done.
The fact that it mentions works as a basis for judgment does not mean that it excludes their lack of faith in God or Christ or vice versa. The fact that human’s practice what is wrong is normally a direct indication that they lack faith in God.
Rom 1:20 For his invisible attributes, namely, his eternal power and divine nature, have been clearly perceived, ever since the creation of the world, in the things that have been made. So they are without excuse.
Heb 1:12 For the word of God is living and active, sharper than any two-edged sword, piercing to the division of soul and of spirit, of joints and of marrow, and discerning the thoughts and intentions of the heart. And no creature is hidden from his sight, but all are naked and exposed to the eyes of him to whom we must give account.
It is my current understanding therefore that those in the resurrection of the unrighteous will be judged as Revelation says, on their works prior to their death based on the scrolls as to whether they get another opportunity at life.
Some humans may not have gotten the opportunity to act on faith in God or Christ, such as mentally handicapped, children etc. From a human standpoint it seems just for such ones to have the opportunity to demonstrate whether they would want to live under God’s eventual rule.
However, those not found in the scroll of Life will be destroyed eternally. And yes, he will raise unrighteous humans not found in the Book Of Life to pass judgement on them. They would have to be raised to receive a fair trial and not one done in absentia and thus not knowing what they did wrong or right.
Eternal life is a gift, but that gift has conditions for attaining it, as is laid out in so many places in God’s Word it can only be attained to by those who believe and exercise faith in Christ Jesus and therefore God. Psalm 49:7-8 and Ephesians 2:8-9