In Galatians 5:18 it talk about if you are of the spirit then you are not under the law. What law do they mean?
The power of the Holy Spirit enables one to live the Christ-like life. For example,
Gal 5:22-23 (NASB)
22 But the fruit of the Spirit is love, joy, peace, patience, kindness, goodness, faithfulness, 23 gentleness, self-control; against such things there is no law.
The ends with the phrase "...there is no law."
The law does not exist in order to prevent people from being nice to one another. Instead, the existence of the law is to prevent people from hurting one another.
1 Timothy 1:9 (NASB)
9 realizing the fact that law is not made for a righteous person, but for those who are lawless and rebellious, for the ungodly and sinners, for the unholy and profane, for those who kill their fathers or mothers, for murderers.
In summary, the "freedom" from the law is not a license to go and hurt more people (and commit more sins), but instead to be free from the law that commands the restraint from hurting people.
In other words, the law does not apply to the fruits of the Holy Spirit because those fruits do not hurt other people, which is the purpose of the law to prevent people from hurting people.
Jesus (Matthew 23:4), rebukes the Pharisees and indeed everyone, who would lay the “yoke of the Pharisees” the burden of self-righteousness, and legalistic law-keeping, on the backs of sinners. Biblical scholars say that the Pharisees added 620 regulations to the ten commandments of God, given at Sinai. Many denominations “condemn” that and “forbid” this, because it is well known that “People who eat shellfish and slow dance always sin more often.”
WHAT LAW IS BEING REFERRED TO?
It is clear from verses 2-4; 6;11 & 14 of Galatians 5, that the apostle is referring specifically to the law of Moses, the law of the Old Covenant. However, this statement by Paul (Gal 5:18) is not a negative comment about the law (which he regards elsewhere as “…holy, righteous and good” (Rom 7:12 NIV). Rather, it is a negative comment regarding the flesh. This is made clear in verse 16 where the stated end is that “…you will not gratify the desires of the flesh.”
SO WHAT IS PAUL SAYING ABOUT THE LAW?
Firstly, the law had a specific function, which Paul has already pointed out in this epistle (Gal 3:19). The New Living Translation renders the first part of that passage thus: “Why, then, was the law given? It was given alongside the promise to show people their sins. But the law was designed to last only until the coming of the child who was promised…”
So the law was given to reveal the sinfulness of the flesh. It does this by speaking to the flesh and demanding a flesh right response, which the flesh is incapable of providing, as a result of its fallen state. The law therefore reveals fallen man’s incapacity to attain true righteousness.
The righteousness promised in the law but which the law, due to the condition of the flesh, was unable to deliver (Gal 3:21). So without the law, sin could not be imputed (Rom 5:13-14).
The problem is that the law couldn’t and didn’t deal with sin, it identified it, but, due to the nature of the sinful flesh, it also magnified its effects (Rom 5:20 NIV).
SO WHAT IS PAUL SAYING ABOUT THE SPIRIT?
Here we get to the heart of Paul’s message. The flesh and the Spirit, he informs his readers, are opposites. In the verses immediately preceding the one under discussion, he makes this point: “For the flesh lusts against the Spirit, and the Spirit against the flesh; and these are contrary to one another, so that you do not do the things that you wish…” (Gal 5:17 NKJ). [There are echoes here of the apostle’s powerful description of how his own flesh naturally functions (Rom 7: 14-15)].
You may desire to do good. You may desire to keep the law: but, since the law speaks to the flesh and demands a flesh response, sin is inevitable if we remain in the flesh (and therefore under the law).
The reason Pauls tells us that we are no longer under the law, is precisely because we now walk in the Spirit and not the flesh. As the apostle so eloquently puts it in the following verse: “But if you are led by the Spirit, you are not under the law (18).
So, to summarise, the law of Moses spoke to the carnal nature and revealed its sinfulness, whereas the Spirit is the power of a new life in Christ (Rom 8:11). The law we now follow, as we walk in the Spirit, is the law of Christ (Gal 6:2).