The Qur'an does not name al-Khidr, but calls him a servant from among our servants:
And they found a servant from among Our servants to whom we had given mercy from us and had taught him from Us a [certain] knowledge. (18:65)
we only know the name al-Khidr from the sahih sunnah.
This verse actually gives the answer saying:
... a servant from among Our servants to whom we ... had taught him from Us a [certain] knowledge.
The Sufis call these kinds knowledge al-'Ulum al-Laduniya العلوم اللدنية bestowal knoiwledge as imam ar-Razi quoted in his tafsir -see here in Arabic- on this verse, saying that al-Ghazali wrote a book to give a proof of the existence of this science. While ar-Razi says that when a person witnesses something or found it or reflected about it there are two possibilities either we may give a verdict and believe it or we don't give a verdict and imagine it. And divided them into two categories one of them is that of gained knowledge and one of them is rather given like the feeling of the pain of others. Ar-Razi also quoted some proofs of the majority view that al-Khidr actually was a prophet().
Sheikh a-Shinqiti said in his Adwa' al-Bayan:
Shaykh al-Shanqeeti (may Allaah have mercy on him) said in his commentary on the aayah (interpretation of the meaning)
“Then they found one of Our slaves, on whom We had bestowed mercy from Us, and whom We had taught knowledge from Us”
“But it may be understood from some aayahs that the mercy mentioned here was the mercy of Prophethood, and that this knowledge which came from Allaah was the knowledge of revelation (wahy)… It is known that mercy and the bestowal of knowledge from Allaah is more general and comes in more ways than via Prophethood. The fact that something general exists does not necessarily imply that something more specific exists, as is well known. One of the indications that the mercy and knowledge with which Allaah blessed His slave al-Khidr came by way of Prophethood and revelation is the aayah (interpretation of the meaning):
“And I did them not of my own accord”[al-Kahf 18:82]
i.e., rather I did them by the command of Allaah, and the command of Allaah is only conveyed via wahy (revelation), because there is no way for the commands and prohibitions of Allaah to be known except through revelation from Allaah, especially with regard to the killing of an apparently innocent soul and damaging a ship by making a hole in it, because committing acts of aggression against people’s lives and wealth can only be validated via revelation from Allaah. Allaah has restricted the method of warning to revelation as He says (interpretation of the meaning):
“Say (O Muhammad): “I warn you only by the Revelation”
the word innama (translated here as “only”) implies limitation or restriction.
Adwaa’ al-Bayaan, 4/172, 173 (Source islamqa #21793)
Al-Qurtobi commented by quoting ibn 'Atiyyah -see here in his tafsir-:
وعلمناه من لدنا علما أي علم الغيب ، ابن عطية : كان علم الخضر علم معرفة بواطن قد أوحيت إليه ، لا تعطي ظواهر الأحكام أفعاله بحسبها ; وكان علم موسى علم الأحكام والفتيا بظاهر أقوال الناس وأفعالهم .
(and had taught him form Us a [certain] knowledge) refers to the knowledge of the unseen (al-Ghayb). Ibn 'Atiyyah: The knowledge of al-Khidr was that of the knowledge about the deeper meanings which were revealed to him, not caring about the apparent rulings and he acted upon them, while Musa's knowledge was that of the rulings and fatwa according the apparent statement of the people and their action.
So al-Khidr was given a knowledge by revelation which Musa actually didn't have. While one of them was giving fatwa according to what he sees and witnesses the other was acting upon what he knew would happen if he didn't intervene.
Therefore our prophet () commented at the end of the long hadith about this story in the Qur'an:
... The Prophet (ﷺ) added, "We wished that Moses could have remained patient by virtue of which Allah might have told us more about their story.
(Sufyan the sub-narrator said that the Prophet (ﷺ) said, "May Allah bestow His Mercy on Moses! If he had remained patient, we would have been told further about their case.") (Sahih al-Bukhari1 , 2 and 3)
Note that at the end al-Khidr again resumes saying:
... And I did it not of my own accord. That is the interpretation of that about which you could not have patience." (18:82)
showing that this comes from a prior revelation.
If I remember well sheikh at-Taher ibn 'Ashur tried in his at-Tahrir wa-Tanwir to make a distinction between the three acts of al-Khidr and explain what was possibly al-Khidr's own action and that of an ordered (revealed) action in each case based on the words of the Qur'an.