There are various ways to approach this question, both philological and literary.
From a philological or textual point of view, we need to look at the source of the statement that Enkidu must die.
None of the manuscripts of the Standard Babylonian version provide an complete text of the beginning of Tablet VII,
where Enkidu's dream is supposed to be. Instead, there is a gap of 30-35 lines immediately following the first line.
The dream is only available in the shorter Hittite version of the epic, which is fragmentary and in prose.
The Hittite version of the epic, however, does not contain the episode about the Bull of Heaven.
But the Hittite version of the dream mentions both the killing of Huwawa (Humbaba's name in the Sumerian poems)
and the killing of the Bull of Heaven.
So from a philological point of view, we believe that the gods decided that Enkidu must die because
the only extant manuscript of the dream, the Hittite version, says so.
When looking at the question from a literary point of view, there are various aspects to consider.
First, there is the relationship between Gilgamesh and Enkidu.
In the Sumerian Gilgamesh/Bilgames poems (which are older and don't constitute an integrated narrative), Enkidu is described as a servant.
For example, in "Bilgames and Huwawa A", Bilgames "called to his servant, Enkidu" (George p. 151).
From this point of view, Enkidu is more "expendable" than Gilgamesh, who is a king.
In the Standard Babylonian version, Enkidu is more than a servant;
Gilgamesh repeatedly calls him a friend and in Tablet III, Gilgamesh's mother Ninsun adopts Enkidu as her son.
(Enkidu has no parents and in Ancient Mesopotamia, orphans were often adopted by the temples in order to "save them the jaws of the dogs", as one text puts it.)
In the Standard Babylonian version, which describes Gilgamesh as two-thirds god and one-third human, Enkidu is still more expendable than his king.
(Curiously, in the available manuscripts of the Standard Babylonian version, Gilgamesh never addresses Enkidu by his name but calls him "my friend".
He starts pronouncing Enkidu's name repeatedly only after his friend's death. The Hittite version is too fragmentary to establish whether the same pattern is present there.
It is not clear whether this is relevant to the decision of the gods.)
Second, which gods are present in Enkidu's dream? They are Anu, father of the gods and Ishtar's father, Ea, the wisest of the gods,
Enlil, "Lord Wind" and divine rules of Earth, and the sun god [Shamash]. Notably absent are Ishtar, whom both Gilgamesh and Enkidu had insulted,
and Gilgamesh's mother Ninsun (who is probably one of the lesser gods, as suggested by Tablet III, where she asks Shamash to protect Gilgamesh during his quest to the Cedar Forest).
Enlil had appointed Humbaba as guardian of the Cedar Forest, so he has a reason to be displeased,
even though Gilgamesh and Enkidu had created a gigantic door for his temple in Nippur to placate him.
It was Enkidu who had come up with this idea (see end of Tablet V). Apparently, the door did not placate Enlil.
Anu had allowed Ishtar to take the Bull of Heaven to earth to exact her personal revenge.
After the death of the Bull of Heaven, he too has a good reason to be angry.
Shamash had always protected Gilgamesh and even helped both friends to kill Humbaba.
There are even lines in Tablet III that it was he gave Gilgamesh the idea to go to the Cedar Forest.
It is only consistent for him to continue defending Gilgamesh and Enkidu.
None of the gods explicitly demands Gilgamesh's death, so letting Enkidu die comes down to a choice for the line of least resistance.
However, neither Enkidu's social inferiority nor the decision of the gods provide an answer to the following two questions:
(1) which of the two men most deserve to die and (2) whose death would most placate the gods?
When we look at both killings they stand accused of, we can see an interesting pattern.
When Gilgamesh and Enkidu have managed to overpower Humbaba the guardian pleads for his life.
Gilgamesh appears willing to spare him but Enkidu urges Gilgamesh to kill him, which Gilgamesh does.
In the fight against the Bull of Heaven, it is Enkidu who advises Gilgamesh on how to kill the Bull:
"Thrust your dagger between nape, horn, and kill-point!" And this is exactly who Gilgamesh does it
(See page 53 in Foster's translation or page 52 in George's translation, which uses the term "slaughter-spot").
By executing the actual killings, Gilgamesh appears to heap more blame upon himself than Enkidu.
In addition, both victims weren't earthly creatures but were both associated with the realm of the gods.
One would expect the gods to exact more than an ordinary sacrifice to placate them, and Gilgamesh, being two-thirds god,
would constitute a much more valuable sacrifice than the orphan Enkidu.
Instead, it is Enkidu who has to take the fall.
It is possible to find two reasons for this.
First, it is possible to see a vague parallel with the custom of appointing a substitute king to divert danger from the real king.
Eckart Frahm (page 140-141 writes):
When a ruler in Ancient Mesopotamia believed that a negaive omen, for example a lunar eclipse, announced disaster,
he could appoint a "substitute king" [Ersatzkönig], who would pro forma temporarily rule in his stead
in order to divert the expected disaster to himself, after which he [the substitute king] was killed.
The parallel with the fate of Enkidu is obviously not become a "substitute king" but being sacrificed to save a king or, in other context, another person.
(The social phenomenon that someone takes the blame for others is well known in other cultures and is still preserved in concepts
such as scapegoat, fall guy and whipping boy.)
Second, and perhaps more convincingly, there is a psychological argument for letting Enkidu die instead of Gilgamesh.
In the first half of the epic, Gilgamesh wants to make a name for himself, which would confer at least virtual immortality on him.
(Being remembered was very important for kings but also for ordinary people in Mesopotamia; see for example the Sumerian poem "Bilgames and the Netherworld".)
However, it is Enkidu's death that causes his fear of dying and that motivates him to go on a quest to Uta-napishti and the secret of eternal life.
This quest is essential to his development as a character.
His desire for immortality is such that he needs to be taught several lessons before he understands its futility:
first, the tavern-keeper Siduri tells him it is useless, then he fails Uta-napishti's challenge to stay awake for six days and seven nights
(he falls asleep immediately) and finally, he loses the plant that would give him back his youth.
Finally, from a purely narrative point of view,
Enkidu's death triggers Gilgamesh's quests in Tablets IX-XI, which allows the narrator to integrate the flood story,
which had originally been an independent story (the Atrahasis story).
Based on the above, I consider it unlikely that Enkidu is being punished for failing to defeat Gilgamesh.
Enkidu had been created after the people of Uruk had complained to the gods about their treatment by Gilgamesh's,
who did not conduct himself as the "good shepherd" he was expected to be.
After he has become friends with Gilgamesh, the epic no longer mentions this inappropriate behaviour.
Gilgamesh starts neglecting his kingly tasks again after Enkidu's death.
- The Epic of Gilgamesh: The Babylonian Epic Poem and Other Texts in Akkadian and Sumerian. Translated with an introduction by Andrew George. London: Penguin, 1999.
- The Epic of Gilgamesh. Translated and edited by Benjamin R. Foster. Second Edition. Norton, 2019.
- Frahm, Eckart: Geschichte des alten Mesopotamien [History of Ancient Mesopotamia]. Stuttgart: Reclam, 2013.