This was evidently because he recognized God as the pinnacle of goodness. Our ability to do good is hindered because of inherited sin.
(‏ مرقس ١٠ :‏ ​ ١٧ ،‏ ١٨‏ )‏ وَمِنَ ٱلْوَاضِحِ أَنَّهُ رَفَضَ ذلِكَ لِأَنَّهُ عَرَفَ أَنَّ ٱللهَ هُوَ أَسْمَى مِثَالٍ لِلصَّلَاحِ .‏