This passage is often used to bolster the claim that Jesus is not God. The usual misinterpretation is that Jesus is saying that He isn't good, because He isn't God.
The opposite is true. In this passage, Jesus is establishing His deity. The Answering Islam site offers a fairly good explanation.
In the central passage of chapter 10, Jesus makes the statement:
I am the good shepherd. (John 10:14) This establishes his claim to
deity in a double way. First, because of the criterion above, since he
calls himself good, and this not only in a general way as "a good
shepherd" (one of many) but as "the good shepherd".
It is a simple syllogism:
No-one except God is good and Jesus is good therefore Jesus is God
Somebody might want to argue that here "good" is only qualifying
something else (i.e. "shepherd"), but we simply observe that in the
original passage (Luke 18:18 above), it was qualifying "teacher". So,
the situation is indeed parallel, and the argument applies.
Second, Jesus calls himself not only "good", but he claims the title
"shepherd". This is a clear reference back to Psalm 23 and, even more
important, Ezekiel 34, where God himself is the shepherd of Israel
(see this discussion). Thus, with this statement Jesus takes upon
himself yet another title of God.
Why do we call him good? Because he is - AND he is the Lord God.
A more succinct answer (with the same outcome) can be found on this article about WJD at Heartlight.
Jesus is challenging the religious leader to wake up and understand
the truth that stands right in front of him. If he is calling Jesus
"good," then he must come to understand that Jesus is God and not play
religious games, but come to truly believe. Jesus isn't denying that
he is God; Jesus is affirming that he is God and that man truly needs
to acknowledge that he is. Eternal questions are not simply religious
speculation, but the core questions of the human soul. Only God can
answer those questions. So if he is going to ask Jesus this question,
he needs to pay attention and place his faith in Jesus' answer. So do