I'll adapt something from my answer to a similar question someone posted a few days ago:
Historical linguists reconstruct languages that were never written down using something called the comparative method. That is, if they can establish that English and German were once the same language that diverged a long time ago (which they are), they can reconstruct roughly what that Proto- language (Proto-Germanic in this case) sounded like by comparing the features of the two. The starting point is comparing similarities between related words (cognates) in two or more languages. If a set of languages share a lot of vocabulary, it stands to reason that they have a common origin. And obviously the more similar the languages, the more closely related they are. So for example the words father in English and vater (father) in German show a close family resemblance because English and German split off from each other relatively recently. Compare that to Latin pater (father) and you can see there is also a family resemblance, but at more of a remove. Do that for many words—and grammatical features, and phonology, etc.—in many languages and you can build up a family tree of sorts showing how each language is related to the others. The result is a language family like Indo-European, which encompasses languages spoken by some 3 billion people around the world that ultimately all descend from a single reconstructed ancestor called Proto-Indo-European, spoken between 5,000 and 10,000 years ago.
From there, linguists can go beyond simply spotting the resemblance and start identifying systematic "laws" of sound change which operated through history and created the differences between the languages. So for example, most words beginning with p- in Latin/Romance languages have relatives that begin with f- in Germanic languages. Pater and father/vater is one example; Latin piscis (fish) and English/German fish/fisch is another. As it turns out, the words beginning with p- were the original form in the common ancestor of the Germanic languages and Latin (because even more distantly related languages still have the p- words). At some point after they diverged, Proto-Germanic speakers began pronouncing ps as fs. By following these sound change laws back up the family tree, linguists can they get a good idea of what the original proto-word sounded like. Here, for example, is Schleicher's fable, a story in Proto-Indo-European—a language spoken over 5,000 years ago and never written down—composed from words that were reconstructed by comparing its many descendants:
Avis, jasmin varnā na ā ast, dadarka akvams, tam, vāgham garum vaghantam, tam, bhāram magham, tam, manum āku bharantam. Avis akvabhjams ā vavakat: kard aghnutai mai vidanti manum akvams agantam. Akvāsas ā vavakant: krudhi avai, kard aghnutai vividvant-svas: manus patis varnām avisāms karnauti svabhjam gharmam vastram avibhjams ka varnā na asti. Tat kukruvants avis agram ā bhugat.
In English:
A sheep that had no wool saw horses, one of them pulling a heavy wagon, one carrying a big load, and one carrying a man quickly. The sheep said to the horses: "My heart pains me, seeing a man driving horses." The horses said: "Listen, sheep, our hearts pain us when we see this: a man, the master, makes the wool of the sheep into a warm garment for himself. And the sheep has no wool." Having heard this, the sheep fled into the plain.
A related question about Ancient Egyptian came in the other day; I rounded up a bunch of posts that could be helpful, one of which leads to many other posts about pronunciation of various ancient languages. If you have follow-up questions, include the relevant user's username in the comment - most of us have notifications turned on
To add on, how do historians know what dead languages sound like? Such as olmec or mayan?
Edit: Ancient Mayan
You may want to cross post to /r/linguistics too, if you haven't already.