Galatians 4:22–26

(Galatians 4:22-26) For it is written, that Abraham had two sons, the one by a bondmaid, the other by a freewoman. But he who was of the bondwoman was born after the flesh; but he of the freewoman was by promise. Which things are an allegory: for these are the two covenants; the one from the mount Sinai, which gendereth to bondage, which is Agar. For this Agar is mount Sinai in Arabia, and answereth to Jerusalem which now is, and is in bondage with her children. But Jerusalem which is above is free, which is the mother of us all.

The Old Testament passage that Paul refers to did not have this meaning at all — Paul just made it all up.

Image Old Testament meaning Paul's meaning
outside God's plan

the bondwoman
Ishmael, born of the flesh;

those outside of God's covenant
Mt. Sinai;

the old covenant of bondage to the law;

in bondage to the church
within God's plan

the freewoman
Isaac, born of promise;

the chosen nation of Israel
Jerusalem from above;

the new covenant of freedom from the law;

the church

Paul substitutes as follows:

Ishmael = Old Covenant

Isaac = New Covenant

I suppose you could say that there is a progression:

Ishmael --> Isaac --> Old Covenant --> New Covenant (=church)

Immediately after the apostles, the early church began to interpret the Old Testament allegorically,looking for references to Jesus Christ. Certainly Paul sets this trend.

Perhaps one way of understanding this allegory is as follows: Just as Isaac the child of promise is vastly superior to Ishmael the child of flesh, in like manner Christ and the church is vastly superior to the old covenant of law.

(Hebrews 8:6) But now hath he obtained a more excellent ministry, by how much also he is the mediator of a better covenant, which was established upon better promises.

At first Abraham interpreted God's promise of a son without faith by acting in the flesh. This corresponds to the nation of Israel which attempted to gain God's favor through ritual and works of the Law. Then Abraham acted in faith and had a son of promise. This corresponds to the church which accepts God's gift of salvation in faith.

(Hebrews 11:17) By faith Abraham, when he was tried, offered up Isaac: and he that had received the promises offered up his only begotten son.

Certainly Paul's conclusions were correct. The difficulty with following Paul's example and constructing allegories from various Bible passages is that we have no guarantee that the truth behind the allegories are correct. Certainly Paul did not have to worry about this. But in modern times there are many wacky teachings supposedly based on the Bible which are derived from using this kind of allegorical methodology. Some examples: