Paul is continuing his stern rebuke here, and it seems he intends his argument to settle the question ("this only would I learn of you"). His rhetorical question is whether the Galatians received God's Spirit through their personal accomplishments or by hearing and believing. This is in no way a condemnation of "works of the law," as Christ Himself commands that we display "good works" to set the proper example to the world, after which He says in no uncertain terms that He did not come to destroy the law (Matthew 5:16-17). These are the same works that Jesus did (Matthew 11:2) and praised (John 3:21; 8:39; Revelation 2:26). Acts 26:20 shows that there are works involved in repentance, and much of James 2 shows the place that works have within our responsibility. To each of the seven churches in Revelation 2-3, Christ says He knows their works—and they are judged accordingly.
Clearly, there is nothing wrong with following God's law; indeed, the New Testament is filled with verses that show that lawbreakers will not enter the Kingdom of God. The question in this verse is not about whether the law is still in effect, whether following it is still required, or whether there is anything wrong with the set of laws that God codified. Rather, the critical point is what part the law plays within our conversion and sanctification, and consequently, what part God plays in the process as well.
On the one hand, there is the implication here that a person does not receive the Spirit by the works of the law, and on the other hand there is the definite statement in Acts 5:32 that the Spirit is only given to those who obey God—those following His law. As with the apparent disparity between Galatians 2:16 and Romans 2:13, these statements are easily rectified when we separate the means by which something is accomplished from the requirements.
According to Acts 5:32, one of the requirements for a person to receive the Holy Spirit, even in a small measure, is obedience to God (lawkeeping). God will not give a measure of His life-giving Spirit to someone who is rebellious or disobedient to Him! The story of Simon Magus (Acts 8:9-24) illustrates this. Simon had the gospel preached to him, and he "believed" and was baptized. These events seem to fulfill Paul's statement in Galatians 3:2: He heard the gospel, and he believed. Would this not qualify as "the hearing [having the gospel preached] of faith [he believed]"? Should he not have then received the Holy Spirit?
Simon the Sorcerer did not receive the power of the Holy Spirit because he did not fulfill the requirement of Acts 5:32. Simon was not obedient to God—he did not submit himself to God but tried to bribe the apostles to lay hands on him. His heart was not right in the sight of God; his actions and intents were "wickedness"; he was "poisoned by bitterness and bound by iniquity." This was not someone that God wanted to entrust with a measure of His mind and power! God only gives His Spirit to those who obey Him.
Even though keeping the commandments is a requirement, it does not entitle one to receive the Holy Spirit. The Holy Spirit is a gift (Acts 2:38; 10:45; Hebrews 2:4), something freely given and not earned. This is the point the Galatians were stumbling over: They did not understand, or did not want to believe, that God's forgiveness, justification, sanctification, Holy Spirit, etc. are all things that God is responsible for. These are His prerogatives, and nothing we do can force Him into doing anything! Romans 9:11 shows that it is by God's election that determines who has his mind opened, not the choice (or the works—same verse) of the individual. John 6:44 shows clearly that God chooses who will enter into the covenant relationship, and without God drawing a person to Him, it is impossible for that person to even know God. I Corinthians 1:26-29 also illustrates that God does the "calling," and He purposefully chooses the weak, the foolish, the base things of the world. A large part of the reason is that nobody can boast (glory) that God called them because they were exceptionally righteous or in any way deserved to be called.
The Galatians seem to have rejected the overwhelming part that God and Jesus Christ play in the salvation process. They thought they were righteous enough, on their own, to have been justified, to receive the Holy Spirit, to attain salvation, etc. The reality is that we are God's workmanship, and He is the only one that can bring our salvation to pass (Ephesians 2:10). While we have a responsibility—to yield, submit, obey, overcome, etc.—even if we perfectly fulfill this responsibility, we are still then doing only the bare minimum. Our works are necessary, but they are not the means by which we are saved, nor, as Paul is saying here, are they the means by which we receive the Holy Spirit.