Remember the purpose of the "law" was to show man he was a sinner. No one could ever keep the law. This young man said "he kept the commandments which Jesus mentioned", but he was not exactly telling the truth. I think Jesus knew this, but he did not say he was a liar. Jesus then tells this young man another thing to do, which I believe Jesus knew there was no way he could do it, in selling all his belonging, and giving to the poor, and then he would have treasure in Heaven. With out having a "vision" of something better in Heaven (treasure) than what we have right now, we will never let go of the stuff we posses in this life.
I find it interesting that when Jesus said,....
John 7:17 If anyone's will is to do God's will, he will know whether the teaching is from God or whether I am speaking on my own authority.
If this young man really believed that Jesus was God, and if he had made a "decision" first to do what ever Jesus said, he would have done it.
How many people want to hear what they must do, and then make a choice whether or not they will do it? It will not be given to them, unless they first make a decision they are going to do it when they hear it.