Question was asked on FB: “How did Jesus attain righteousness?”
First of all, Jesus is God, Creator, Messiah, Judge, from everlasting to everlasting (Psalm 90:2); therefore, Jesus is righteous by His very nature as Deity (John 1; Colossians 1; Hebrews 1).
Second, Jesus attained His righteousness in the flesh (Philippians 2) through the virgin birth (Luke 1; Genesis 3:15). Jesus was conceived in the womb of the virgin woman by the will and power of the Holy Spirit thereby permitting Jesus to circumvent the sin-nature that is transferred genomically (via federal headship) to all of human-kind throughout every generation (Romans 5:12). Jesus, who is God spiritually, was born in flesh absent the sin-nature physiologically; Jesus walked among mankind for 33.5-years in absolute sinlessness and fulfilled the righteous requirements of the Law i.e. perfection for us (James 2:10; 2 Corinthians 5:21; John 8:46).
The Law could not provide mankind righteousness (a right standing) with the Father due to our sin-nature inherited from our father, Adam, but Jesus did for us what we could not do for ourselves; that is, Jesus fulfilled the Law for us and offers His righteousness to us in exchange for our sin if we will trust in Him as our Lord (2 Corinthians 5:21; Romans 8:3).
Having pleased the Father through perfect obedience to the Law, Jesus voluntarily walked to the horrors of a Roman Crucifixion where His innocent blood was shed as a blood sacrifice for the sins of the whole World (John 3:16-18; 1 John 2:2). With this one selfless act of love, Jesus died a substitutionary death for you and for me and paid our sin-debt for us; that is, a debt owed to the Father that we, in our sin-nature, could never pay (Romans 8:3).
As a result of Jesus’ faithfulness at the Cross, God the Father agrees by Covenant (Matthew 26:28; Hebrews 8:10; 10:16) to forgive and redeem anyone who believes that His Son, Jesus Christ, died to pay their sin-debt (John 3:16-18) and along with this forgiveness, the Father agrees to impute the perfection/righteousness of Jesus over the life of the one who believes that Jesus is Lord (2 Corinthians 5:21); in addition, the Father agrees by Covenant to give the Holy Spirit to the one who believes in Jesus as Lord (Ephesians 1:13-14; John 14:16) and the Holy Spirit then indwells the believer and becomes their personal Teacher-Tutor (1 John 2:27) as the Spirit walks the redeemed in the daily process of sanctification (Galatians 5:16-26); that is, the Holy Spirit guides the believer in the ways of obedience to God’s will and righteousness as the Law is written upon their heart (Hebrews 10:16); in addition, the Holy Spirit prepares the believer for service in the coming Kingdom of God, the New Jerusalem, which will be established, subsequent to the Millennial Reign of Jesus, on a New Earth within a New Heaven (John 14:3; Revelation 21); it is there that the redeemed in Jesus Christ will serve our resurrected God in our resurrected bodies, forever (Philippians 3:21; Revelation 21).