There are many such contradictions which are intended to be used as teaching tools -- e.g. to specify contrast between two different things, and they only appear as a contradiction if you assume they are referring to the same thing.
Here is another example:
1 John 1.10 "If we say that we have not sinned, we make him a liar, and his word is not in us."
1 John 3.6 "Everyone who resides in him does not sin. Everyone who sins has neither seen him nor known him."
And you can resolve this tension with the dualism of the old man and the new man. The new man is born from above and cannot sin, and the new man is within us. The new man cannot sin. The old man can only sin and can do nothing but sin. Thus these passages apply to two different "ones", the one from above and the one from the earth.
And I think the point here is the one born of the flesh also does good deeds, but these do not profit us at the end because the flesh always points things to itself, either praising itself for doing a good work and thus lifting ourselves up in such a way as the good work does not result in an eternal reward.
This is a theme started in Matthew 5 and continues up to the final parable in Matt 7. For example:
"Whenever you fast, do not be sullen like the hypocrites, for they
make their faces unrecognizable in order that they may be seen fasting
by people. Truly I say to you, they have received their reward in
full!" Matt 6.16
"Therefore whenever you practice charitable giving, do not sound a
trumpet in front of you, as the hypocrites do in the synagogues and in
the streets, in order that they may be praised by people. Truly I say
to you, they have received their reward in full! But you, when you
practice charitable giving, do not let your left hand know what your
right hand is doing, in order that your charitable giving may be in
secret, and your Father who sees in secret will reward you." Matt
So these examples of works that do not survive to Judgement Day culminate with the devastating "I never knew you" in the final parable of this sequence.
Now contrast that with the parable of sheep and goats in Matt 25:31-46, where Jesus praises the sheep for things the sheep didn't even realize they did, and he condemns the goats for things the goats didn't even realize.
So there is a message here that those things that make us satisfied on earth as to our good works are not going to be the ones that benefit us in the life to come.
2 Cor 4.7 "For we do not proclaim ourselves, but Christ Jesus as Lord, and ourselves as your slaves for the sake of Jesus. For God who said, “Light will shine out of darkness,” is the one who has shined in our hearts for the enlightenment of the knowledge of the glory of God in the face of Christ. But we have this treasure in earthenware jars, in order that the extraordinary degree of the power may be from God and not from us."
Now contrast this with Mark 9:41
For whoever gives you a cup of water to drink in my name because you
are Christ’s, truly I say to you that he will never lose his reward.
Here, the good deed is happening not because the person wants to benefit themselves but because they see a need and respond to it, that is, there is an element of selflessness to giving this cup of water, which is different from doing the good deed in order to be seen doing the good deed or to obtain some kind of personal benefit. That creates a mystery, in that it's hard to do a good deed without trying to benefit yourself, which I think is why the deeds the sheep are praised for are the ones they didn't know they did, while the deeds that we believe benefit us are the ones that we don't profit from. The deeds we do out of seeing a need and responding with a selfless desire to meet a need outside ourselves, those are the ones that survive
And if I parcel out all my possessions, and if I hand over my body in
order that I will be burned, but do not have love, it benefits me
nothing. Love is patient, love is kind, love is not jealous, it does
not boast, it does not become conceited. 1 Cor 13.3-4