It bases this compliment on the story in this week’s reading (Gen. 39) about Joseph resisting the lures and wiles of Potiphar’s wife. He says to her, “How can I commit such great evil, and sin against God?”
What seems to make a Tzaddik, if we base ourselves on this passage, is not simply that he does the right thing. Everyone should do that automatically. Joseph is special because he shows two additional character traits. He will not let himself sin against his earthly master; nor will he let himself sin against his Heavenly Master.
He has a sense of responsibility towards Potiphar, not just because he is scared to be found out but because he has a moral duty to the employer who reposes his trust in him. He has a sense of duty to God, even though the world might never find out if he sins.
The whole of the Shulchan Aruch begins by warning us that even when no human being sees what we do, we are always in the presence of God and answerable to His expectations.