ommandments are the core of the old covenant between God and Israel, with Moses as mediator.
It was common for a king then to make a covenant with the people he reigned over, with the basics of that agreement written on clay tablets and put up for public display, with the rest of the covenant kept in their archives.
Jesus came to "fulfill" the law; not keep it. To keep the law is to comply with the law, regardless of the condition of the heart. For instance, a person could hate another, yet refrain from murdering the other, but the heart of hatred remains.
It comes out in Scripture that love fulfills the law, and Jesus in his acts and sacrifice demonstrated his love for his creation.
As far as why God gave them to Israel? Because they were prone to do those things contrary to this law. Moses declared this law was to be a witness against them; to show them they were a stiff-necked, rebellious and faithless people. The law then convicted them of sin and showed them to be what they were, and not what they thought they were. They thought they were "God's people" thus good in God's sight.