Of course, we can't know the answer to this in any certain way because the men did not leave notes explaining themselves.
Perhaps the most likely explanation is that the men were both patriots and dedicated soldiers. This means that they cared a great deal about their home "countries" and about their fellow soldiers. Both of these would be reasons for staying and fighting so that the rest of the Greek armies could get away and regroup instead of getting slaughtered as they retreated.
It may be also that the men were willing to die because of the heroic tradition in Greece. These were men who would have been raised on the stories of the Trojan War and who would have taken seriously the idea that the gods favored those who were valiant. This might have been another reason to stay and fight.
Again, we simply can never know for sure.
It is because of the militaristic culture of the Spartans that we have few records regarding Sparta. The militaristic culture of Sparta emphasized the production of strong, disciplined young men and placed little emphasis on the formal education of reading and writing. It was expected that the citizen-soldier be ready to fight and if need be die for their country. King Leonidas and the 300 soldiers remained at Thermopylae to prevent the further incursion of the Persian Army into Greece. All most likely knew it was going to be their death. They proceeded to hold the position as it was not in the culture of the Spartans to retreat.