How do linguists/historians know that the famous Egyptian pharoah was called (and pronounced) “Ramesses”? How do they know the mythical Sumerian king was called Gilgamesh? Or the cities Uruk and Akkad?
A slightly different question- does the pronunciation of the names we remember (Alexander the Great, Hammurabi, Ahkenaten, etc.) jive with how native speakers at the time would have pronounced it? Did Alexander the Great’s buddies call him “Alexander”, or his father “Phillip” (I think this one might be “Alexandros” and “Phillippos”, but I don’t know about Hammurabi, Gilgamesh, or the Egyptian kings)?
This is only a part of it, but if you have poetry and can look for things like meter and rhyme, that will give some data points to start with. Also, if you can see their names written in other languages that might be more well known, that will also give you a clue.
In the case of ancient Greek, we have lots of examples of writing (both historical and literary) to draw from. Naturally, the Rosetta stone (being written in Greek as well as Egyptian) was a big help wrt Egyptian.
I imagine that it has to do with the connections between languages more than anything else.
For an excellent read on a tangential topic, see Simon Singh’s book The Code Book, chapter 5, “The Language Barrier”
He gives a fairly good layman’s explanation of how the Rosetta Stone allowed us to understand Egyptian hieroglyphs. Also included is an interesting discussion of the process of decrypting ancient tablets written in Linear B.
I remembered this book because of your mention of Ramses:
The following quote from page 215:
Clearly, he is talking about using pre-existing knowledge of how to pronounce Ramses in order to break the hieroglyphics code on the Rosetta stone, but you can get an inkling of some of the tricks that might be involved.
ETA: And of course, as John Mace pointed out, the Rosetta stone was written in Greek, Demotic, and Hieroglyph. Ramses is mentioned. Presumably in a nice-to-pronounce Greek form.