There's an old saying: "He did all the right things, but for all the wrong reasons." That saying applies to Christian belief and behavior. Not only are we to do what is right, but the motivations which cause us to perform those actions must also be right.
There's a passage of Scripture which identifies the motivations which culminate in the commission of sinful acts, and the motivations which culminate in the performance of righteous acts. Scripture tells us that no motivation listed as an act of the sinful nature is to be accepted as the origin of a righteous act, and no motivation listed as the fruit of the Spirit is to be accepted as the origin of a sinful act. Each set of motivations culminates in diametrically opposed actions:
So I say, live by the Spirit, and you will not gratify the desires of the sinful nature. For the sinful nature desires what is contrary to the Spirit, and the Spirit what is contrary to the sinful nature. They are in conflict with each other, so that you do not do what you want. But if you are led by the Spirit, you are not under law.
The acts of the sinful nature are obvious: sexual immorality, impurity and debauchery; idolatry and witchcraft; hatred, discord, jealousy, fits of rage, selfish ambition, dissensions, factions and envy; drunkenness, orgies, and the like. I warn you, as I did before, that those who live like this will not inherit the kingdom of God.
But the fruit of the Spirit is love, joy, peace, patience, kindness, goodness, faithfulness, gentleness and self-control. Against such things there is no law. Those who belong to Christ Jesus have crucified the sinful nature with its passions and desires. Since we live by the Spirit, let us keep in step with the Spirit. Let us not become conceited, provoking and envying each other. (Galatians 5:16-26,NIV)
Those who are nonchristians and perform acts which appear to be righteous are not to be judged by us as other than righteous. Only God can see into their hearts in order to know what the motivation for their actions was. But as Christians we believe that as a result of our accepting the sacrifice of Jesus Christ as cleansing us of our sins, God sends his Spirit to rein in our sinful nature, and then implants in us the new nature (the fruit of the Spirit) which we need to have in order to say and do the words and actions which God wants of us.