I've been preparing for a Sunday School lesson and found Matthew Poole's commentary on this issue very edifying:
Galatians 3:21 (POOLE)
Ver. 21. Is the law then against the promises of God? God forbid: though it be thus, yet there is no such opposition between the law and the promises, as that either of them make the other useless. Far be it from me (saith the apostle) to assert any such thing! They are not contrary to one another but subservient to one another.
For if there had been a law given which could have given life; for if there had been a law which could, by our perfect performance of it, have given us a righteousness, wherein we might have stood righteous before God, then righteousness should have been by the law; then men might have hoped to have been justified and accepted of God by me for such obedience; then indeed the law had been against the promises, they holding forth another righteousness, viz. the righteousness of God from faith to faith.
22 But the scripture hath concluded all under sin, that the promise by faith of Jesus Christ might be given to them that believe.
Galatians 3:22 (POOLE)
Ver. 22. But the Sripture hath concluded all under sin: it pleased God to give a law, which, if Adam had continued in his estate of innocence, might have given life; but considering man in his lapsed state, that now is not possible: Ro 2:10: There is none righteous, no not one: and Eph 2:3: We are all children of wrath.
That the promise by faith of Jesus Christ might be given to them that believe; that the promises of life and salvation might be given to those who, according to the new covenant of the gospel, should receive and accept of the Mediator, and the terms of salvation which God offers to us in the gospel; where these promises are exhibited upon condition of believing. Though, upon our first reflection upon it, it may seem strange to us, that God, having in his eternal counsels fixed the salvation of man upon a conenant of grace, and his believing in Jesus Christ, should in time first propound a covenant of works: Do this, and live; yet, upon second thoughts, this will appear necessary; for till man was a transgressor by breaking the law, and violating the first covenant, there was no room for a Mediator, no cause for men´s applying themselves to a Mediator. God therefore first gave out the covenant of works, and suffered man to break it; and then he revealed the Mediator to lapsed man; that so they who should believe in him might obtain the promise of life, to which by the fall they had forfeited their right.
23 But before faith came, we were kept under the law, shut up unto the faith which should afterwards be revealed.
Galatians 3:23 (POOLE)
Ver. 23. Before faith came; before the covenant of grace, or the doctrine of the gospel, or Christ himself, was revealed.
We were kept under the law; the apostle either speaks of all mankind, of whom it is true, that until God´s revelation of the covenant of grace, they had no other way of salvation made known to them than by the law of works; or else of the Jews, to whom, though before Christ there was a revelation of the gospel, yet it was more dark and imperfect, so as they
were kept under the law, but few apprehending any other way of justification than by the works of the law.
Shut up unto the faith which should afterwards be revealed; but the apostle saith they were but shut up under it; God never intended it as that by the observance of which they should be saved; but as even then, to those whom he intended to save, he made a more secret revelation of his gospel, so he had now more fully and plainly revealed the way of salvatiou which he had from eternity established.
24 Wherefore the law was our schoolmaster to bring us unto Christ, that we might be justified by faith.
Galatians 3:24 (POOLE)
Ver. 24. The law, both the law contained in ordinances and the moral law,
was our schoolmaster; serving us in the same stead that a schoolmaster in a school doth, who only fitteth children for higher degrees of learning at universities.
To bring us unto Christ: the ceremonial law showed us Christ in all his types and sacrifices; the moral law showed us the absolute need of a Mediator, as it showed us sin, accused and condemned us for it; and it showed us no help either for the guilt of sin contracted, or against the power of it.
That we might be justified by faith; so that God´s end in giving us the law was, that we might be fitted for Christ, and obtain justification by believing in him.
25 But after that faith is come, we are no longer under a schoolmaster.
Galatians 3:25 (POOLE)
Ver. 25. After that Christ, the object of saving faith, was in the fulness of time revealed, and the gospel, which is the doctrine of faith, was fully revealed and published, the time of our nonage was over.
26 For ye are all the children of God by faith in Christ Jesus.