The Affection, 17-21
The pronoun "they" in verse 17 refers back to Galatians 2:4 "false brethren unawares brought in." These false brethren affect the true believers with their zealous work that they may bring the Galatians under the bondage of the law. The effect is not a good one, because it destroys the freedom that we have in Christ (See Gal. 5:1). They do this so that they may steal the affection of these believers away from Paul and his true Gospel unto themselves and their damnable doctrine of salvation by the law.
Paul here challenges the believers that they may be zealous, but only in a good thing. In other words, the truth matters. He is concerned about them, because he is like a mother who has travailed to birth in his work for them, and they were born again by the message of grace that he brought to them. Now he is travailing "in birth again" as he did in the beginning when they believed in Christ, but now his travail is for their further maturity in Christ so that false brethren will not be able to turn them away from their teaching and preaching the true Gospel of Jesus Christ. At this point he stands in doubt of them, that perhaps they have not been truly born again as they may profess.
The Allegory, 22-31
These verses relate a familiar story from the Old Testament of Abraham, Hagar, and Sarah. We know that the son born of Abraham by Hagar was not the child of promise that God was going to use to both bring a holy posterity to Abraham and to fulfill a promise that would eventually be an allegory to teach salvation by grace.
Ishmael was born of the bondwoman. This illustrates how we through Adam were born in bondage to sin and the condemnation of the law. Isaac was born of Sarah through a promise given by God.
Hagar represents Mount Sinai; Sarah represents Mount Zion (Jerusalem which is above). We see a good contrast of these two mountains in Hebrews 12:18-24, which read soon. Now we are "the children of promise," 28.
There is, then, persecution from those born under bondage toward those who are born free. Therefore, we are to "cast out" the bondwoman (Mount Sinai, the law) and her son (whatever doctrines spring from dependence upon the law).
Instead of cooperating with the Gospel of the law or assimilating its teachings with the true Gospel, we should "cast out" that carnal and damnable doctrine and trust Christ alone for salvation, so that we can be children "of the free." Romans 8:2 For the law of the Spirit of life in Christ Jesus hath made me free from the law of sin and death.