The short answer is that we don't. The pronunciations we use today are our best guess at how the ancients pronounced their words.
For your two examples.
We know that Sumerian had an immense influence on the Semitic language Akkadian. Because Akkadian was a Semitic language, and we have a wealth of data about how related Semitic languages were pronounced, we can therefore deduce (by applying the regular sound laws) a reasonable approximation of how Akkadian would have been pronounced.
Taking that back one step further, we can then use that best guess at Akkadian to approximate how we think Sumerian would have been pronounced.
Happily, there are no ancient Sumerians around today to tell us we're wrong!
Ancient Egyptian hieroglyphs pose a different set of problems. The written form of the language didn't generally record vowel sounds. So, when we transliterate the name of Nefertiti from the hieroglyphs, we actually get:
Nfr t jy tj
We add the extra "e"s to make it pronounceable. This isn't just a wild guess though. In the Greco-Roman period, stelae were often carved in multiple languages (typically, Egyptian hieroglyphs, and Greek, although they could also be incised with a demotic version of the text). The best known example of this is, of course, the Rosetta Stone.
Also, the Coptic language is a descendent of the ancient Egyptian language, so we have some guidance there.
Additionally, names were often recorded in the records of other societies. They wrote them phonetically, as they heard them, and so are a good guide to how the Egyptians pronounced those names.
A good case-in-point here is the Pharaoh Tutankhamun. His name was usually written as:
("living image of Amun"). But this places the name of the god Amun at the start of the name, to honour the god. Under normal rules we would transliterate this as:
Amun twt ankh
But we know, from records of other contemporary civilisations that it was actually pronounced "Tut-ankh-amun".
The question of vowel sounds in the ancient Egyptian language is an interesting one. For example, most popular books about Egyptian hieroglyphs will confidently tell you that the vulture:
represents the letter "a". In fact, it represented what we call the aleph, and there is still no clear agreement on the sound that it represented. It may be the "glottal stop" and this is currently the majority view among Egyptologists. For convenience, we pronounce it as an "a", but we are by no means certain that is how the Ancient Egyptians pronounced it.
The aleph discussed above should not be confused with the aleph found in Semitic languages. That seems to correspond with the single reed in Egyptian hieroglyphs:
Now, most popular books on Egyptology will tell you this should be pronounced as "e" or "i" or "j". The truth is far more complex.
One of the most common offering inscriptions from ancient Egypt is the, so called, "htp di nsw" offering formula. From the Middle Kingdom onwards this would take a form similar to:
which can be transliterated as:
ḥtp dỉ nsw wsỉr nb ḏdw, nṯr ꜥꜣ, nb ꜣbḏw
One again, you'll note there are very few vowels here. The inscription translates as:
An offering that the king gives to Wsir [Osiris], lord of Busiris, the Great God, Lord of Abydos ...
(Busiris and Abydos being the two main cult-centres of the god Osiris in ancient Egypt)
I said above that the formula has that form from the Middle Kingdom onwards. This is because, from the Middle Kingdom, the god Wsir (or "Osiris" to give him his more familiar Greek name) was the main god of the afterlife. In the Old Kingdom, however, that role was given to the god Inpw:
He is more familiar today by the Greek version of his name "Anubis" (you may have already guessed that from the "determinative" figure at the end of his name).
This is of particular relevance to the discussion here, since you will notice that, when written in hieroglyphs, the name Inpw begins with the single reed hieroglyph we saw above, and which I noted is usually said to represent an "e", "i", or "j".
When written in Akkadian cuneiform, the name of the god was rendered as a-na-pa, and, as we have already seen, the Greeks made it "Anubis". So, the single reed clearly wasn't pronounced as an "e" or an "i" in this instance, but rather as something closer to an "a"!
Part of the reason for the confusion is simple. Egyptian names had meaning. Stephen Quirke captured this concept quite neatly in his book Who Were the Pharaohs?, when he observed that
The essence of the individual was encapsulated in the name given to the child at birth.
The hieroglyphs used to write that name also had meaning.
Foreign names, however, did not have any special meaning. They could just be spelled out letter-by-letter using the hieroglyph that sounded closest to that letter. Thus we have the names foreign rulers, and also of the Macedonian Greek Ptolomeic kings from later inscriptions, like the Rosetta stone. These were rendered into hieroglyphs, and it is often those vowel sounds are then used when we try to pronounce ancient Egyptian names.
(There are dozens of tourist shops that will provide the same service for you today in Cairo or Luxor. For a small fee, they will produce "your name in hieroglyphs" written on a sheet of papyrus as a nice memento of your holiday. Amusingly, my name ("Iain") is invariably rendered as:
which actually bears no relation to how it is generally pronounced ("Ian"), or indeed, how it should be pronounced (something close to the Scandinavian "Jan"), but which does match the letters to hieroglyphs!).
When thinking about how words should have been pronounced, let us consider modern English for comparison. We have common words like "bath", "scone" or "either", which are pronounced quite differently in different part of the UK today. Those differences centre around how the vowel sounds should be pronounced. And those vowels are just what we are missing in many Egyptian inscriptions!
Furthermore, we have to remember that the Egyptian language was in use for millennia. Just think about how the English language has evolved from the Old English, spoken by our Anglo Saxon ancestors a thousand years ago, to the language we speak today.
As a student, I learned to read Middle Egyptian hieroglyphs. If the characters are well-formed, I can usually manage middle Egyptian hieratic as well. (Demotic of any period is still pretty-much just dots & squiggles to me!)
However, I can also just-about read inscriptions in Old Egyptian and Late Egyptian (albeit that does involve reaching for the dictionary rather more often than I would have to with a Middle Egyptian text). But it is important to be aware that there are differences in the written forms of the words though, and that, in turn, probably meant that they were pronounced differently as well.
Which brings me back to the beginning. The pronunciations that Egyptologists use today are just our best guess, based on the information available to us, at how the ancient Egyptians would have pronounced their words.