Matthew 22:37-40
37 Jesus said unto him, Thou shalt love the Lord thy God with all thy heart, and with all thy soul, and with all thy mind.
38 This is the first and great commandment.
39 And the second is like unto it, Thou shalt love thy neighbour as thyself.
40 On these two commandments hang all the law and the prophets.
What did Christ mean by this, why not just give the Ten Commandments...
The issue is that some of God's commandments appear to conflict with each other, such as when God commanded priests to rest on the Sabbath while also commanding priests to making offerings on the Sabbath (Numbers 28:9-10), however, it was not the case that priests were forced to sin by breaking one of the two commandments no matter what they chose to do, but that the lesser commandment was never intended to be understood as preventing the greater commandment from being obeyed. This is why Jesus said in Matthew 12:5-7 that priests who did their duties on the Sabbath were held innocent, why David and his men were held innocent, and he defended his disciples as being innocent. Likewise, there are issues like whether we are permitted to tell a like in order to preserve someone's life, so it is because of issues like these that we need to know which commandment is the greatest.
How can we know which commandment is the greatest? For example, the greatest commandment might be the one with the highest penalty for breaking, the commandment that is repeated the most, the commandment that the Israelites were most frequently criticized for breaking, the commandment that promised the greatest reward for obeying, the commandment that God specifically said to remember, and so forth. All of God's laws are essentially about how to love God or how to love our neighbor, which is why Jesus said that those are the greatest two commandments and that all of the other commandments hang on them. For example, if we love God and our neighbor, then we won't commit adultery, theft, murder, idolatry, rape, kidnapping, favoritism, and so forth for the rest of God's commandments.