The rich young ruler became an illustration of what not to do. Jesus teaches his followers about the disadvantages of wealth from what happened with the rich young ruler.
Jesus continuously presents the correct way to live life. He does this sometimes by telling stories about people who have lived their life the wrong way. This contrast makes it clear which way we are to live our one and only life.