To be righteous means to do the right thing.
Goodness is a state of being, and righteousness is an act of doing.
God is righteous because He is good, and He only does good. And since all He ever does is good, we can ascribe righteousness as one of His inherent attributes. God doesn't just do good sometimes, He is good. He doesn't just do the right thing sometimes, He defines what the right thing to do is, and does it. So, He IS righteous.
To put it into modern theological terms, righteousness is the works-based aspect of faith. Paul tells us that we are saved by faith alone (and not by works), but James encourages us to live out our faith in righteousness because faith without works is dead. What James is getting at in His letter in the New Testament is the very heart of righteousness. Paul tells us that we cannot be saved and then go on sinning, and John agrees with him saying that anyone who has been saved cannot possibly go on sinning. And they are both agreeing with James - anyone who loves God and has the Holy Spirit active within them, through faith, cannot help but to do righteousness - because God (the spirit in them) is righteous.
You see, it is not by our own efforts that we become righteous, but by marriage to our savior Jesus Christ (where the two shall become one flesh) that we take on His righteousness. It is our faith that binds us to Christ, and it is His righteousness that is borne out through us after that.
And God's righteousness is not just in relation to us, or what we think is good. God's righteousness envelopes everything. We see things happening around us and we label them as good or bad. We even question God about why He would let things happen that we label bad. But God is not threatened by the things that we call bad. There is no bad that God cannot turn into good. When someone we love dies, we call that bad, but God has the power even to reverse death - and we certainly call that good. No matter how bad we might think things are, God has the power to do good in it, and to use it for good - because He is righteous, and He always does good. There is nothing so bad that God cannot do good in it and from it.
It is through God's righteousness that He created everything that exists. His goodness radiates outward as His love, and together they form the foundation, inspiration, and motivation for everything He does. They are not distinct attributes of God, but we identify them with different labels by ascribing them to God in particular ways. God is good in and of Himself. God is love in His goodness in relationship to us. And God is righteous in the goodness of all His actions. You might even think of them as a trinity of God's attributes. Three attributes all with the same essence.
As for us, when we are righteous we are acting out God's presence within us. We are, in fact, acting in and as His image. And it is through righteousness that we spread God's kingdom through the world. Remember that righteousness is the outward act of the inward good and love of God, and that is why Paul says to the Corinthians that any act done without love is meaningless. There can be no righteousness without goodness and love.
And it is through righteousness that we become trustworthy to God. As we act out God's goodness and love more and more, He gives us more opportunities, more challenges (to grow from), and more responsibilities to continue in righteousness. This reminds me of the story of Job...
Job was righteous and faithful to God, so much that God trusted him to withstand the attacks of Satan so that God could prove a point to Satan. Satan didn't come to God with the intention to hurt Job. God pointed Job out to Satan, and then Satan, of course, wanted to attack Job. But God didn't hesitate to let Satan attack Job, because He knew He could trust Job. God only told Satan not to kill Job, and then, after the attack was over, God rewarded Job with twice as much as He had before.
And, if you think that was mean of God to do, how do you think Job feels about it now that He's in heaven? It might not have been a pleasant experience to go through, but I'm sure Job's rewards in heaven are even greater than the ones he received back on earth. And what might have seemed like a bad thing in the moment turned out to be something that God used for the good of His kingdom, and for the good of everyone who reads the book of Job in the Old Testament.
God only does good. And when we are bound to Him, and united to Him, in faith, we can do good. There is no good without God, there is no love without God, and there can be no righteousness without God. Because He is all of them, all at the same time, in every moment, fully and completely.
For from him and through him and for him are all things. To him be the glory forever! Amen. (Romans 11:36)
Psalm 145:17 - The Lord is righteous in all His ways, gracious in all His works.
Jeremiah 9:24 - "But let him who glories glory in this, that he understands and knows Me, that I am the Lord, exercising lovingkindness, judgment, and righteousness in the earth. For in these I delight," says the Lord.
James 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.
Romans 6:1-2 - What shall we say then? Are we to continue in sin that grace may abound? By no means! How can we who died to sin still live in it?
1 John 3:9 - No one born of God makes a practice of sinning, for God's seed abides in him; and he cannot keep on sinning, because he has been born of God.
1 John 3:6 - No one who abides in him keeps on sinning; no one who keeps on sinning has either seen him or known him.
Job 1:8 - The Lord said to Satan, “Have you considered My servant Job? For there is no one like him on the earth, a blameless and upright man, fearing God and turning away from evil.”
Job 2:3 - The Lord said to Satan, “Have you considered My servant Job? For there is no one like him on the earth, a blameless and upright man fearing God and turning away from evil. And he still holds fast his integrity, although you incited Me against him to ruin him without cause.”