I am curious about mortality rates and patterns in these very methodical battles. It is my uneducated guess that soldiers in the front of tightly packed infantry formations had almost no chance of surviving the whole battle. How did ancient soldiers feel about this? Was there a prospect of higher glory in the first rows that made up for the higher risk? Were they confident in their skills and/or divine protection?
1/2
I'm going to break this down into a couple of separate questions to make sure I cover all sides. But the first thing I should point out (and which you may already know) is that ancient battles of heavy infantry were not like they're depicted in the movies. The chaotic melee you see in Gladiator or Game of Thrones, with formations all mashed together and people fighting enemies all around them, has no relation to actual history.
In organised warfare, heavy infantry fighting is all about order. The two sides will always try to keep their formation. Their survival depends on it. If they lose order, they lose cohesion; if they lose cohesion they lose control and morale; if this happens they will break and the enemy will slaughter them. The kind of all-out brawl you see in movies would be utterly disastrous for any army, an absolute guarantee that the battle would be lost. It was more important for hoplites to keep their nerve and stay in formation than to kill enemies. The side that stuck together longer would win. Even if hoplites tended to run and charge into battle, the actual fighting would often take place at spear range, with two lines of men poking at each other, hoping to pry the enemy formation apart.
In this kind of battle, the men in the front rank were all-important. If they were eager and tough, they would stand their ground and face the enemy, and the enemy would buckle. If they were scared and skittish, they would break first and take their entire phalanx with them. The front rank not only had to lead the rest of the phalanx forward to spear range (or closer) but also had to keep them there for as long as it took to win.
With that context in mind, we can start to answer your question.
How did you end up in the front rank?
In the pre-phalanx warfare of the Archaic period, the answer is easy: you put yourself there. The Homeric epics and the poetry of Tyrtaios are both full of encouragements to warriors to go forward, not to hang back and leave the work to others. Apparently there was a choice; there was room enough to go back and forth between the sharp edge of dueling "front-fighters" (promachoi) and the mass of men at the back. If you hung back you'd have a better chance to survive, but only those who fought in front could gain glory and fame. If you're a young man from a rich house and you're looking to prove yourself, forward you go, and make sure your javelin won't miss.
Things become more complex when the phalanx develops out of earlier, loosely organised formations of heavy infantry around the time of the Persian Wars. The phalanx has fixed ranks and files, probably lined up reasonably close together (possibly with shields touching). In the phalanx there is no room for men to hang back or skirmish forward. Everyone has a fixed place and the integrity of the line depends on them keeping it. There are formal punishments for leaving your place in the line (lipotaxia, literally "leaving the formation," later becomes synonymous with desertion).
So how did they decide who stands in front?
On the one hand, the Greeks knew that a smart commander would put his bravest men in front and his oldest and wisest in the rear. The older men would be the least inclined to run, and would keep the rest facing forward; meanwhile the bravest and most eager for glory would lead the way. This was an ancient principle for the deployment of any group of warriors, and it would be formalised in the later Macedonian pike phalanx. As the 4th century BC Athenian general Xenophon put it, "unless its first and its last are brave men, the phalanx is good for nothing" (Education of Cyrus 6.3.25).
On the other hand, even if the Greeks knew this, we have very little evidence that they regularly put it into practice. While we get some signs that commanders would assign their men to particular places, we are also told that individual men could choose where they wanted to be. Both Thucydides and Plato show hoplites finding themselves a place in the formation as they came up from the camp or city. The orator Lysias had his client Mantitheos boast that he volunteered to fight in front during the campaign against Sparta in 394 BC:
Then after that, gentlemen, there was the expedition to Corinth; and everyone knew in advance that we would have to fight. Some were trying to shirk their duty, but I contrived to have myself posted in the front rank for our battle with the enemy.
-- Lysias 16.15
This sort of thing would only be possible if there was no fixed positioning, no officer ordering each man to his place. Even if there was a more formal order, it was acknowledged that individual men could have their placement changed. Glory-seekers like Mantitheos could get themselves placed in front, but others would probably try their best to secure a position further back.
But why would anyone do what Mantitheos did? This is why I mentioned Homer and Tyrtaios earlier. In pre-phalanx warfare the only way to win glory in combat was to fight in front, and to be seen doing it. Even if the regular phalanx of the Classical period no longer offered room for such individual heroism, all Greeks were still raised to think of Homer as the highest guide to excellence; they found ways to apply his vision of manly courage to their own world. In this case, they tried to be seen fighting in front because it was proof of their selfless dedication to their community, their indifference to danger in a battle for the common good. Those who wanted to be seen as good men would try to give proof that they were not cowards. Those who wanted to lead others would first have to give the right example. There would be plenty of men eager to form the front rank of a phalanx despite the risk. Indeed, there would be plenty of Greek citizens who would be gravely insulted if a commander positioned them at the rear, since it showed implicit doubt in their courage and commitment.
The only exception to this chaotic self-sorting system was the Spartan army. Spartan hoplites of the Classical period prided themselves in a relatively advanced system of tactical drill in which Spartiates (full Spartan citizens) were probably instructed from the moment they reached adulthood. But Sparta faced a unique problem in the organisation of its phalanx: most of the hoplites that filled its ranks were not full Spartan citizens. Due to the small number of full citizens the formation was fleshed out from the mid-5th century BC onwards with perioikoi, freeborn non-citizens, who had not been drilled in the Spartan fashion. To make sure the entire phalanx could operate to a reliable standard, the Spartans came up with a simple solution. As long as the men in the front rank were all Spartiates, they could lead the way, all the rest had to learn was to follow them. This was how the Spartan phalanx was drilled to act in unison in a way that other Greek phalanxes could not. But the price of this tactical solution was that the entire front rank had to be formed by precious Spartiate officers. The Spartans could be sure that these men would be motivated and dependable, but there was little room for further selection.
While these systems were quite different (and Xenophon went to great length to persuade the rest of the Greeks to adopt the Spartan system, apparently to no avail), they had one similar result: in both systems the front rank typically consisted of the commanders of the army and their most dedicated followers. If we can believe the very late testimony of Plutarch, the Thebans actually tried to guarantee this by creating an elite unit whose sole purpose was to form the front rank(s) of the citizen hoplite phalanx in battle. While it was quickly realised that the unit would be more useful if it fought separately, the initiative makes clear how important it was to have a reliable front rank - even if it meant exposing your best men to the highest risk of death.