Hieroglyphs ARE phonetic, but with one omission that I'll get to later.
Jean-François Champollion in his "Letter to M. Dacier concerning the alphabet of the phonetic hieroglyphs" wrote
It is a complex system, writing figurative, symbolic, and phonetic all at once, in the same text, the same phrase, I would almost say in the same word
Fortunately, the language spoken in Ancient Egypt would eventually "evolve" into the Coptic language. While Coptic has largely been replaced by Arabic in Egypt (surviving mostly as a liturgical language for the Coptic churches in Egypt, like Ecclesiastical Latin or Church Slavonic), Coptic provides at least a little insight into the ancient Egyptian language.
The Rosetta Stone was the key, as it contained the same text written in Hieroglyphs, Demotic, and Greek. The Greek part could easily be translated (although there were some odd uses of Egyptian administrative jargon that puzzled translators for a bit).
(Side not, Demotic is just a "simplified/cursive" version of Hieroglyphics that was used for less formal writing environments that evolved from Hieratic. For this reason, along with the fact that Egyptologists represent these two with Hieroglyphics for legibility, and the fact that cursive scripts need huge ligature tables, Unicode doesn't have a dedicated block for either Hieratic or Demotic, stating that a Demotic font could just use the encodings for the Hieroglyphic characters)
Unfortunately, all there of these are "logographic" writing systems. Like Chinese.
Fortunately, the Ptolemaic dynasty offered linguists a huge advantage: the names "Ptolemy" and "Cleopatra" were enclosed in cartouches in all three sections, and since these were Greek names instead of Egyptian, they were written using phonetic characters. This means that there was a time period from 305 BC to 30 BC were (nearly) every ruler was named "Ptolemy" or "Cleopatra" and Greek was an important language of government.
Thus we were able to confirm the pronunciation of the characters used in Ptolemy and Cleopatra's name. From there, we were able to deduce the pronunciation of the rest using the Rosetta stone and writings from other artifacts. For example, Jean-François Champollion was able to identify the pronunciation of Ramesses and then Thutmose (how he got Ramesses is explained below).
However, there was one small problem: Hieroglyphs don't always include vowels.
This is not particularly unusual. Alphabetic scripts that don't include the vowels are called an "Abjad" (as opposed to an "alphabet". The Coptic script that replaced Demotic is one such example of this, as are Arabic, Hebrew, Phoenician, Aramaic, and several other scripts in the region. Under this system, readers are just expected to know the appropriate vowel.
However, while the Rosetta Stone inscriptions of "Ptolemy" and "Cleopatra" include vowels, others such as "Ramesses" (rˁ-ms-sw) or "Thutmose" (dhwty-ms) do not.
So how do we know what vowels they used? Well, we don't know for sure.
We can make some guesses though. "Ramesses" uses the "sun" hieroglyph, and the Coptic word for "sun" is "ra" (as is the name of the Egyptian sun god). In addition, Exodus 1:11 mentions Ramesses as a name of one of two cities built by the Israelites, so assuming the Hebrew transmission of the vowels in that name was correct until it got passed into a language with vowels (like Greek), we can be reasonably sure it's correct. We can also check against loanwords from nearby contemporary languages, and check texts by foreign authors (e.g. Greek) to see how they rendered Egyptian vowels into their language.
We can make some reasonably sure guesses (guesses, not certainties) for figures like "Thoth", "Horus", "Osiris", and so on, but the general tradition is "if we don't know, use an E".
Thus, obscure figures like Medjed just use "E"s.
This is complicated by the fact that the Egyptian that was spoken in the time of Khufu was over 2000 years old by Cleopatra's time. As you can imagine if you've ever tried to read the original version of Beowulf, language changes over time.
Sources:
Loprieno's Ancient Egyptian: A Linguistic Introduction
Parkinson's Cracking Codes: The Rosetta Stone and Decipherment
Hieroglyphs could be phonetic; there’s a symbol that accompanies them that lets the reader know if they’re to be read as phonemes or as pictographs. Even so, they don’t know for certain how a specific glyph was to be pronounced in every context. Another issue is that Egyptian, like the Semitic languages, didn’t write vowels, so what we have are consonant clusters like R’-ms-sw and Khfw.
In many cases what Egyptologists did was look at the names written in other scripts (Demotic, which used the Greek alphabet, or the scripts of neighboring cultures with whom diplomatic correspondence was exchanged) to see how they were rendered and try to reconstruct the names that way. Even so, we have to account for things like differing accents and vowel shifts over time, so, in all honesty, we have a best guess, but a number of them are probably slightly off from how they would have been said at the time.