First, What was the situation in Galatia at that time? Once that is established, the reason for the OT quote should become clearer.
On Paul and Barnabas’s first missionary tour, they had established congregations of new believers in Antioch of Pisidia, Iconium, Lystra, and Derbe (Acts 13:13-14:28). Then arose an increasingly heated debate amongst Jewish Christians who maintained that Gentile converts should practice Judaism in order to be Christians. But the apostles saw the danger of such teaching, resisting it by showing that any return to the law would enslave those who had been set free in Christ. Paul’s letter to the Galatian Christians seems to have been written shortly before this debate was settled by the Jerusalem council (circa AD 49 or 50). Thereafter, the idea of these ‘Judaizers’ (who claimed that Gentile converts had to be circumcised) was dealt with. But prior to that, these Judaizers had visited the Galatians and begun spreading this deceptive deviation from the gospel. This was why Paul wrote to them. He needed to stop them being misled by “another gospel, which is no gospel at all” (1:6-9). He builds his case up to write of Abraham’s faith and how his miracle child of promise (by Sarah) represents Christians who are free, but the children of the bond-woman (Hagar) are not free (3:1-4:31).
Second, What does this OT quote mean in context? If you ask about the context of the original statement in Isaiah 54:1, then it is God speaking to Jerusalem (as representing Israel especially during the exile). He speaks as the ‘husband’ of a disobedient, forsaken ‘wife/widow’ now being called back into favour and glory. Of some significance, this section of prophecy follows that of the suffering servant who would be crushed but then see his ‘offspring’. The restored ‘woman’ will rejoice in yet having many children, miraculously so (see Isaiah 66:7).
But if you ask about the context in the original application of Paul to the Galatian Christians, the Third question needs addressing: Why does Paul cite this Isaiah passage here?
The rest of Paul’s letter gives the answer but only a summary can be stated here. Paul applies Isaiah 64:1 to Abraham’s wife, Sarah, who was barren beyond hope of ever bearing a child. He contrasts her with Hagar, the bond-woman who bore Abraham a child naturally. In time, that son founded four nations. What of the offspring of Sarah’s miracle child, Isaac? That was what Paul was using to teach the Galatians about the miracle of them having become children of God, due to the one represented by Isaac – Jesus Christ, the Son of God – and faith in him alone. His point was that if they went back to legalism (as with circumcision and law-keeping) they would be children of slavery. They had been liberated in Christ and so the Spirit-born children of God would be far more numerous than the natural-born children of Israel. Why would they even think of going back to bondage, as represented by Hagar the bond-woman’s situation? Jerusalem above was free and was their ‘mother’.
That is why Paul concludes his allegory with,
“Therefore, brothers, we are not children of the slave woman, but of
the free woman. It is for freedom that Christ has set us free. Stand
firm, then, and do not let yourselves be burdened again by a yoke of
slavery. Mark my words! I, Paul, tell you that if you let yourselves
be circumcised, Christ will be of no value to you at all. Again I
declare to every man who lets himself be circumcised that he is
required to obey the whole law. You who are trying to be justified by
law have been alienated from Christ; you have fallen away from grace”
(4:31-5:15).