The history of Ishmael and Isaac illustrates the contrast between attempting justification before God in the flesh versus through faith in the grace of God.
Paul encourages the Galatians to live in accordnace with the spiritual riches of God's grace rather than returning to the "beggarly elements of law and legalism.
The giving of the Law did not affect justification by grace through faith alone. The purpose of the Law was to point us to our need for the promised Messiah.