Here is the verse in context.
16Now to Abraham and his seed were the promises made. He saith not, And to seeds, as of many; but as of one, And to thy seed, which is Christ.
17And this I say,
that the covenant, that was confirmed before of God in Christ, the law, which was four hundred and thirty years after, cannot disannul, that it should make the promise of none effect.
18For if the inheritance
be of the law,
it is no more of promise: but God gave
it to Abraham by promise.
19Wherefore then serveth the law? It was added because of transgressions, till the seed should come to whom the promise was made; and it was ordained by angels in the hand of a mediator. 20Now a mediator is not
a mediator of one, but God is one.
21Is the law then against the promises of God? God forbid: for if there had been a law given which could have given life, verily righteousness should have been by the law.
22But the scripture hath concluded all under sin, that the promise by faith of Jesus Christ might be given to them that believe.
Paul's writings were done this way, many times. He would ask a question as in a debate with someone there is a certain terminology for it, but at this time I can't remember what it is. I will find out though.
In any case. Paul ask, "Wherefore then serveth the law?" You have to go to verses 16-18 to find out why he ask.
v16, Paul is speaking about the promise made to Abraham and his seed. He emphasis that the promise was made to one seed, which is Christ.
v17, He is telling the church, that the promise or covenant was confirm before of God in Christ, the promise wasn't given through the law, which was given 430 years after the promise was given. The law also couldn't disannul the promise, if it did it would make the promise no good.
v18, The promise that God made to Abraham and his seed, Christ, was an inheritance, if it had been from the law, it wouldn't have been a promise, but it was given to Abraham by promise. The law doesn't trump God and His promises.
v19 (now to the question at hand) Wherefore serveth the law? other words, do we serve the law? He then explains why the law was made, because of transgressions. Other words, because of the transgressions of the jews at the time the laws where made, was the reason for the laws to be made. And the law is what lead men to God, until the seed (Christ) came. He didn't come to destroy or to get rid of the Law, but to enforce it, he even enhanced a few in explanation of them.
So that was the long answer.
The short answer is, the transgressions of the jews at the time the law was made. Those transgressions is why God put the laws into written form.
Remember, keep the verse in context with the other verses around it. I tell others sometimes to do the 20/20 rule...if you find a verse that stumps you, read 20 verses ahead of that verse and 20 verses after that verse. Asking Holy Spirit to help you to understand, the principle(s) He is trying to show you.