The key to unlocking this mystery lies in the concept of a Federal Head: by being in an ancestor we inherit their inward nature, and as that nature manifests in our own behavior we also inherit the standing of that ancestor before God. (1Co 15:22) In that sense we all have a federal representative before God; as he stands or falls before God, so do we.
All of us were born in Adam; he’s our common ancestor, and a sinner; when he sinned in the Garden we were there in Him, participating with him in that sinful act, and we died in him when he died. (Ro 5:17)
Not only did we inherit guilt for the original sin by being in our father Adam, we also inherited his evil nature, such that we all start out voluntarily engaging in sinful acts just like he did: we are all made sinners. (Ro 5:19) All of us start out in Adam as children of wrath just like everyone else (Ep 2:3), the god of this world operating in and through us (vs 2) as he pleases. (Jn 8:44a) We each start out this way, with Adam representing us before God as a sinner.
Yet just as we’re initially born sons of Adam, in receiving Christ we become sons of God. (Jn 1:12) This is no more an act on our part than being born physically is; being born of God (vs 13), conceived and begotten by Him according to His own will with the word of truth (Ja 1:18), is an act of God imparting life to us (Ep 2:5), moving us to trust in Him and love Him, as He becomes one with us. (1Co 6:17)
The sons of God are now in Christ, having a new federal Head, no longer in Adam; since Christ has perfect standing before God, so now also do we who believe. (Ro 8:1) Just as we were guilty in Adam’s sin, we are now innocent and pure before God in Christ because of Christ’s obedience, being made the righteousness of God in Him (2Co 5:21), counted perfectly righteous through the perfect obedience of Christ. (Ro 5:19)
Further, as we were all made actual sinners through the offense of Adam, such that we all inherited his evil nature and participated in it through voluntary acts of disobedience, so we who believe in Christ also inherit the holy nature of Christ such that we voluntarily walk in righteousness (Ro 5:19), set apart by the Spirit unto obedience. (1Pe 1:2)
Christ justly becomes our federal Head as we believe in Him, representing us before God and containing us within Himself, because He is willing to die in our place and become our sin when He has no sin of His own. (2Co 5:21) He is punished as a sinner when He is not a sinner; so the justice of God is honored as He justifies believers. In believing on Christ we experience a divine transaction, the exchange of our guilt for His righteousness: God sees the innocent travail of Christ and is satisfied on our behalf. (Is 53:11)
God is not unjust to receive us as righteous, even though we were born in Adam, because we have now been born spiritually into a new federal Representative: Christ Himself; we inherit His perfect righteousness as well as His righteous nature — while Christ becomes an offense to God on our behalf, and suffers everything we deserve for our sin. So, God can be just, and the justifier of anyone who believes in Jesus. (Ro 3:26)
Federal headship is both positional and practical – we recognize our position in Christ through the ongoing transformation of our inward nature into the likeness of Christ by the power of God. (2Co 5:17) Only being made a new creation in Christ can put us in right relationship with God. (Ga 6:15) The one we are in, who represents us before God, either Adam or Christ, and our nature and behavior, disobedient or obedient (Ro 2:6-8) — it all goes together; the one does not exist without the other. (Mt 12:33)
It is of God that we’re in Christ (1Co 1:30); salvation is a miracle we can’t live without. (Mt 19:26) The gospel is simply amazing, something no one could possibly invent: the wisdom of God in a mystery, which He ordained before the world unto our glory, and His. (1Co 2:7)