Who said to him: why do you ask me? Here he presents the response. First he responds, as is found in Mark, why do you call me good? But here, why do you ask me? Both can be understood. But what Matthew says, why do you ask me? has no difficulty; but according to what Mark says, the Arians adopted the error, saying that the Father is good by essence, the Son by participation; therefore they held the Son to be unequal to the Father. But it should be noted that he says: one is good, God. But by the name of God is understood the Father, and the Son, and the Holy Spirit: hence from this every other... creature is excluded, because it is not good by essence. But why does he respond in this way? Jerome says that he responds to the man's mind, who was commending that goodness which is customary in a man; because they adhered more to the traditions of men than of God, as is said above at 15:6: you have made void the commandment of God for your traditions. Therefore he rebukes him, because he was asking of him as of a good man, and not as of God. But what is it that he says, why do you ask me about the good? He says this as knowing his disposition, because he did not have the mind to obey the good, and every temporal good is imperfect and a shadow in comparison with the divine good; Isaiah 64:6: all our justices are as the rag of a menstruous woman. Hence all these goods are from God; therefore if you wish to have them, ask of him: for he alone is good; Psalm 135:1: praise the Lord, for he is good. Therefore have recourse to God. If you wish to enter into life, keep the commandments. For some have imperfect life, some perfect life, and some are totally outside of life, as those who are in sin, or unbelievers, because the just man lives by faith (Heb 10:38). Some therefore have an incipient and imperfect life, as the just in this world; but those have a perfect life who are already in eternal life; hence if you wish to enter into life, keep the commandments, because man is led in through the commandments. Ezekiel 20:11: I gave them my commandments and showed them my judgments. But were the commandments sufficient for salvation? I say no, except through faith in the mediator and through charity; hence the Apostle in Galatians 2:21: if justice be by the law, then Christ died in vain. Likewise Proverbs 7:2: keep my commandments, and you shall live.
Source: Commentary on Matthew