Language change, including phonetic changes, proceeds slowly and for the most part without language users being fully in control, or even aware of it. (You might ask why. The intentional component of language change for a speaker is limited by the listener's capability of understanding their "wannabe futuristic" pronunciation. That limits the amount of language change executed by a single generation of speakers to something smaller than the typical redundancy ratio of the language - except for an off topic scenario called "language shift" where a multilingual population starts using an entirely different language for talking to their parents than for raising their own children in.)
This rigid consistency of language change is what gives historical linguistics its wings. Retrospectively identified laws of language change are believed to operate more consistently across an entire dialect than would be assumed for execution of nearly any other changes in societal norms. For example a certain stressed vowel might evolve into a diphthong, and we would expect that it would do so in every word that contained that stressed vowel before the change (and in no word where it is unstressed). We might not see the stress rules from the writing system in use before the change, and perhaps the stressed/unstressed distinction wasn't preserved to the later dialects, but a hypothetical vowel change like this might help us reconstruct stress positions in that older language if we can only be sure that the sound law operated so consistently. Knowing stress positions we may be able to deduce tons of other things using similar methodology.
This consistency also allows us to generalize from anecdotal evidence of pronunciation as captured through the written language. Rhymes, typo patterns, transcriptions of personal names in bilinguial texts, pronunciation distinctions preserved in some but not all descendant dialects, and a lot more. These methods often don't directly suggest how a certain abstract sound was pronounced in an extinct language, but they can at least uncover the phonology (the abstract structure of pronunciation including how many distinct phonemes there were), phonotactics (which combinations were permissible), and especially into what kind of attested, or previously reconstructed pronunciations those combinations eventually evolved.
Then you can form various theories as to the original pronunciation of those abstract sounds in various words and you can evaluate those theories using available anecdotal evidence.
Nobody claims that we know perfectly how, just for an example, Ancient Greek was pronounced. In fact we do know that those guys didn't have national TV and radio broadcasts and that they therefore must have had even more dialectal diversity than we experience today. But linguists were gradually able to reconstruct quite a lot of this dialectal variability (in space, in time, etc.) of both writing and pronunciation - well, to the extent to which at least written language evidence of Ancient Greek is available.
For languages that didn't use phonetic writing systems, or that adopted a writing system created for an entirely unrelated language, or for reconstructed languages for which we don't even have any direct written evidence, all this is much more difficult and even the best available theories remain debatable. Often we just don't have any clue how a certain word (written with a certain character) was pronounced in a particular language. Specialists will have a way to refer to such a character in speaking, but they will know that it's just a substitute.