It was a blocking action to buy time for the rest of Greece and Sparta to assemble their armies to stop the Persian invasion. It had to be fought to buy time. The Spartans and the other Greeks at Thermopylae bought precious time for the rest of Greece with their lives ! You can find all the sources you need online but here is the Wiki info.
Battle of Thermopylae - Wikipedia, the free encyclopedia
en.wikipedia.org/wiki/Battle_of_Thermopylae