Jesus' statement is a response to what the man said:
17 And as he was setting out on his journey, a man ran up and knelt before him and asked him, “Good Teacher, what must I do to inherit eternal life?” 18 And Jesus said to him, “Why do you call me good? No one is good except God alone. (Mark 10 ESV)
17 καὶ ἐκπορευομένου αὐτοῦ εἰς ὁδὸν προσδραμὼν εἷς καὶ γονυπετήσας αὐτὸν ἐπηρώτα αὐτόν διδάσκαλε ἀγαθέ τί ποιήσω ἵνα ζωὴν αἰώνιον κληρονομήσω 18 ὁ δὲ Ἰησοῦς εἶπεν αὐτῷ τί με λέγεις ἀγαθόν οὐδεὶς ἀγαθὸς εἰ μὴ εἷς ὁ θεός
In terms of the Gospel, Mark gave the answer before the question was asked:
13 And they were bringing children to him that he might touch them, and the disciples rebuked them. 14 But when Jesus saw it, he was indignant and said to them, “Let the children come to me; do not hinder them, for to such belongs the kingdom of God. 15 Truly, I say to you, whoever does not receive the kingdom of God like a child shall not enter it.” 16 And he took them in his arms and blessed them, laying his hands on them. (Mark 10)
One must come to Jesus and receive the kingdom of God like a little child to have eternal life.
Had the man been present when Jesus taught, the "rebuke" is because he wants something more to inherit eternal life: "Good teacher what [more] must I do to inherit eternal life?" In this sense the literary effect is for the benefit of the reader who might question whether entrance to the kingdom of God can really be that simple. If the man had been present, a more reasonable question might be, "Good teacher, how can I [a grown man] come to you like a child?"
Good is ἀγαθός, which, as the OP notes, is used to describe others who are not God. The simple way to reconcile what Jesus said with the use elsewhere, is to preserve the character of the word, which is an adjective, not a noun. In other words, "Why do you call me good [teacher]. No one is good [teacher] except God alone."
Even if the implied sense of "teacher" is discounted, the adjective lacks a noun or pronoun and in that way what Jesus said cannot be used to claim an exclusive application of "good" to God: as the other uses in Scripture show. "No one is good except God" is not an exact equivalent to "God is a good God."
If the implied "teacher" is presumed, then the sense of what Jesus says takes on additional significance. Again, had the man been present for the earlier message, Jesus rebuke is not about the word "good" but in the application of the word to teacher. That is, if the use of adjective means only God is a good teacher why do you call me "good teacher?" Notice how the man responds to the rebuke:
And he said to him, “Teacher, all these I have kept from my youth.” (Mark 10:20)
He no longer calls Jesus "good" and while the pericope ends with the man leaving because of his unwillingness to sell his possessions, the overarching issue is his unwillingness to insist Jesus is in fact "good" and come to Him as a child.