One of the first things I learned in Latin class was that we were going to learn the formal ancient pronunciation style, and that it was different from what the Catholic church uses today in that the letter V was pronounced like a W in modern English, and that there were reasons for thinking this, developed by scholars who carefully studied the existing texts from the time. Much of the rest of the pronunciation is pretty similar to formal Italian, which apart from all the regional accents is rather regular. Venice was also not overrun between ancient times and medieval times, providing more continuity of evidence.
That is, linguists and phoneticists are very patient and detail-oriented people who have spent lifetimes deducing and discussing and coming up with understandings that seem to make the most sense, though it’s possible they may be mistaken on some points or details, as clearly there is no actual way to hear an example. However there is quite a lot of contemporary rhyming poetry and some discussion of language, which has been analyzed by such folks.
There is a nice paper/article on the subject which in sum answers your question in section 3, copied below:
“Do we know how the Romans pronounced Latin?
Surprisingly, yes. The details of the reconstruction are given in W. Sidney Allen, Vox Latina (written in English), Cambridge, 1965. There are several main sources of knowledge:
* The Latin alphabet was meant to be entirely phonetic. Unlike us, the ancient Romans did not inherit their spellings from any earlier language. What you see is what you get.
* Language teaching was big business in Roman times, and ancient Roman grammarians give us surprisingly detailed information about the sounds of the language.
* Languages derived from Latin give us a lot of evidence. In fact, many of the letters of the alphabet are pronounced the same way in French, Spanish, Portuguese, and Italian. It stands to reason that the original Latin pronunciation has survived.
* Spelling errors made by the ancient Romans are very informative. If two letters are often mixed up, they must sound fairly similar. Likewise, if two letters are never mixed up, we know they sounded different. [example snipped by Zaku]
* Finally, transcriptions into other writing systems, such as Greek and Sanskrit, often pin down the ancient pronunciation of Latin very precisely.”