In this famous epic story, Endiku seems to have the role of acting as foil to Gilgamesh and reminding Gilgamesh of what it is to be human. At various stages in the narrative Endiku prevents Gilgamesh from completely forgetting who he is and acts as a kind of link to humanity. Consider, for example, the following incident. When Gilgamesh is about to kill Humbaba, Humbaba pleads for his life and promises that he will serve the gods. Gilgamesh is tempted by this proposal, in spite of the way that Humbaba is depicted as an evil, deceitful creature, and it is only Endiku's words that encourage him to kill the giant after all:
Endiku feared his friend was weakening
And called out: Gilgamesh! Don't trust him!
As if there were some hunger in himself
That Gilgamesh was feeling
That turned him momentarily to yearn
For someone who would serve, he paused...
Throughout this epic, therefore, we can see that Gilgamesh's weakness is his excessive pride. His relationship with Endiku who is a human is something that helps to humble Gilgamesh and to remind him of what it means to be human.
My personal view is that Enkidu teaches Gilgamesh only indirectly, through his death, about what it is like to loose a loved one. Otherwise, Enkidu seems to have similar character flaws to his companion, encouraging the king to forego mercy and defy the gods by slaying Humbaba, and insulting Uruk's patron goddess, Ishtar. My suspicion is that Enkidu's death comes home to Gilgamesh most forcefully after he meditates upon the flood story. The parallel between the senseless slaughter of the flood that evokes the gods' grief and the unnecessary violence of the two heroes that leads directly to Enkidu's death and the king's extreme reaction is unmistakeable. The requirement to show mercy and deal justly with both subjects and enemies is driven home to Gilgamesh by his own experience of senseless loss. Consequently, the long list of the king's achievements in the introduction to the epic deliberately omits any mention to the slaying of Humbaba and the Bull of Heaven, focusing rather on what the Gilgamesh has done to safeguard and protect the lives of his people. Gilgamesh finally learns that it is better to save life, like Ea, than to follow Enlil on a path of thoughtless destruction.