This is another of the well-known parables, the Good Samaritan.
The parable arose out of an expert in the law (the Old Testament Law, that is) questioning Jesus. We all have questions for God and out of many differing motives. Occasionally it is because we genuinely want to know something. At other times it can be out of anger or frustration. Sometimes it is to accuse or trap, as were most of the questions from the Pharisees and teachers of the law. This question may have had a genuine intent, or may have been trying to test Jesus.
As was normal, Jesus replied by asking the questioner a question. Questions are very important, and questioning ourselves is important as it can often reveal the truth about ourselves. The man replies with a good solid Biblical answer. Indeed Jesus used the same answer Himself elsewhere (Mark 12:28-31).
Jesus commends the answer, but then adds "do these things and you will live". Knowing the facts is not enough, we need to do them as well (James 1:22).
The man "wanted to justify himself". Justify here could be seen in the sense of wanting to prove that he was qualified to inherit eternal life. Or it could be taken in the sense that he wanted to show that he was superior to Jesus, so he couldn't allow the exchange to finish with Jesus "on top".
So Jesus then tells the famous parable. Apart from the injured man, the key actors are the priest, the Levite and the Samaritan and it is the Samaritan who gets things right. Samaritans were a despised people by the Jews, looked down on both ethnically and spiritually.
So this tale has multiple purposes. It shows what true love means. It shows what God really values, which is faith put into practice, not mere outward form. And it shows that God has little regard for many of the distinctions we draw.
Jesus closes by asking the man who was a neighbour to the injured man. The questioner has no choice in his answer. The key part is Jesus' final words here, "go and do likewise".