To understand Romans 6:16-18, you must read it in the context of the whole of Romans 6.
You must also understand what Paul meant by the word ‘righteousness’. This is defined in Romans 5:17 as ‘the gift of righteousness’.
For as by one man’s disobedience many were made sinners, so by the obedience of one shall many be made righteous.
Moreover the law entered, that the offence might abound. But where sin abounded, grace did much more abound:
That as sin hath reigned unto death, even so might grace reign through righteousness unto eternal life by Jesus Christ our Lord.
What shall we say then? Shall we continue in sin, that grace may abound?
Certainly not! How shall we, that are dead to sin, live any longer therein?Romans 5:19-6:2
Knowing this, that our old man is crucified with him, that the body of sin might be destroyed, that henceforth we should not serve sin.Romans 6:6
God sent the Law into the world for the purpose of showing people that they are sinners. When sin increased, grace increased even more through the gift of righteousness for those that believed in Christ [Romans 5:17, 5:20].
Paul says it is not possible for you to remain in sin anymore, and for grace to cover it up [Romans 6:1-2]. So there is no more increase of sin for you, and therefore there is no extra grace needed to cover up any extra sin.
Paul says all this is true because you died to sin through a spiritual baptism into Christ [Romans 6:2-3, 1 Corinthians 12: 13, Galatians 3: 26-28]. When you were baptised into Christ, your spirit died with Christ to the world and was then raised with Christ in newness of life [Colossians 2:12, 3:3].
When your spirit died with Christ, your spirit died to your sinful flesh [Galatians 5: 24], including the sin in your sinful flesh. This is spiritual circumcision [Colossians 2: 11-12].
Therefore, you died to the sin in your sinful flesh and it is not you anymore. Since the sin in your sinful flesh is not you anymore, any acts of sin done in your sinful flesh do not get accredited to your account.
Consequently, you remain permanently righteous before God. You do not add any extra sin to your account because your righteousness has been sealed through spiritual circumcision [Romans 4:11, Colossians 2:11-12].
Likewise reckon ye also yourselves to be dead indeed unto sin, but alive unto God through Jesus Christ our Lord.Romans 6:11-14
Let not sin therefore reign in your mortal body, that ye should obey it in the lusts thereof.
Neither yield ye your members as instruments of unrighteousness unto sin: but yield yourselves unto God, as those that are alive from the dead, and your members as instruments of righteousness unto God.
For sin shall not have dominion over you: for ye are not under the law, but under grace.
After establishing that you are permanently righteous before God [Romans 5:1, 6:1-2], Paul then concentrates on how you are to deal with the sin in your flesh.
He says that you are to reckon yourself dead to sin [Romans 6:11], which means that you are to know and act like you are dead to sin.
This means you are to practically trust God (yield your members to God) that you are an instrument of righteousness – that is an instrument of ‘the gift of righteousness’ [Romans 5:17, 6:13]. What this means is that you are meant to trust God that you are permanently righteous before Him and that therefore you do not need to put the sin in your flesh under the Law.
If you do this reckoning of yourself dead to sin, then you will not put yourself under the Law. Since the Law is the power of sin [1 Corinthians 15:56, Romans 7:8], sin will not therefore not reign in you [Romans 6:14].
What then? shall we sin, because we are not under the law, but under grace? Certainly not!Romans 6:15-18
Know ye not, that to whom ye yield yourselves servants to obey, his servants ye are to whom ye obey; whether of sin unto death, or of obedience unto righteousness?
But God be thanked, that ye were the servants of sin, but ye have obeyed from the heart that form of doctrine which was delivered you.
Being then made free from sin, ye became the servants of righteousness.
Paul then deals with the question of will you sin/do error if you do not put yourself under the Law [Romans 6:15].
His answer to that question is: No.
Paul’s explanation of this statement is that when you believed the Gospel of Christ you yielded yourself to righteousness [Romans 1:16-17, 6:16-17]. This righteousness is ‘the gift of righteousness’ [Romans 5:17].
So Paul says that you yielded yourself to ‘the gift of righteousness’ and are therefore now a servant of ‘the gift of righteousness’ [Romans 5:17, 6:18].
He says that as a servant of ‘the gift of righteousness’ your obedience or disobedience is to ‘the gift of righteousness’, not to the Law [Romans 6:16, 6:18].
So then, you will only sin/do error if you do not serve ‘the gift of righteousness’.
To not serve ‘the gift of righteousness’ is to walk against the truth that you have ‘the gift of righteousness’.
Therefore, you will only sin/do error if you walk contrary to the truth that you have ‘the gift of righteousness’, not if you do not put yourself under the Law. (This is similar to what Paul says to the Galatians when he says: “O foolish Galatians, who hath bewitched you, that ye should not obey the truth” [Galatians 3:1]).
SUMMARY OF ‘ROMANS 6:16-18’
Romans 6:16-18: Christians do not do error if they leave the Law. They only do error if they walk contrary to the truth that they have ‘the gift of righteousness’.