If, as it has been said, William Shakespeare invented hundreds of new words for use in his plays, how did his contemporary audience know what he meant
Shakespeare's penchant for making up new words has become somewhat overstated over the years -- Shakespeare loved him some neologisms in his writing, but these words were seldom far removed from other words and phrases which were already in common use. These new words weren't made up out of whole cloth, but for the most part combined or created from already-commonplace words; their linkages to those preexisting words made their meaning immediately accessible to their first hearers and readers. Take a line like "Look in mine eye-balls, there thy beauty lies" from Venus & Adonis. If you know the word "eye" and you know the word "ball", both attested in English since ~1200 CE, and you know that the structure of an eye looks a bit like a ball, you get the picture.
Right off the bat, the Elizabethans loved neologisms -- neologisms could be useful, they could be evocative, they could sound good, and all those things are literary assets in an era before a single formalized standard of "correct English." Whether or not Shakespeare personally invented all of the neologisms he used, he used them pretty liberally -- he used compound words composed of previously-attested and familiar words (think "birthplace" or "barefaced") and converted previously-attested nouns and verbs into adjectives and vice versa, while borrowing freely from continental languages like Italian and French to straight-up import useful words that were already passingly familiar to Anglophone hearers. Shakespeare also employed neologisms that used already-familiar prefixes and suffixes to create new words -- a torturer tortures, a manager manages, a jointress is a woman who partakes in a jointure, and so on. But Shakespeare seldom seems to have employed neologisms whose meaning would be totally unfamiliar upon first hearing, for pretty much the reason you've outlined -- a word whose meaning was totally opaque would be a stumbling-block to audience understanding rather than enhance their understanding. I wouldn't go so far as to say none of the new words attributed to Shakespeare were unfamiliar enough to give a contemporary listener pause, but very few of them are all that obscure relative to contemporary Early Modern English word usages.
There are some special cases alongside the ubiquitous instances that pop up in Internet listicles and Snapple facts -- coinages employed by Shakespeare that simply didn't enter into common use afterward. Some such coinages never entered into wide use simply because their usage in context was so idiosyncratic -- it seems like cheating to count "to unprovoke" as a brand-new word when it mainly appears in Macbeth for the purpose of an erectile dysfunction joke, likewise "to dispark" in Richard II or "to discandy" in Antony and Cleopatra. These are all useful words in the context of specific poetic images and situations in Shakespeare's plays, but they haven't gotten much traction elsewhere. Other Shakespeare coinages are too cumbersome for commonplace use but perfect for the poetic image they invoke -- the verb "to incarnadine" from Act 2 Scene 2 of Macbeth might be on the obscure side, but I'm not sure if it would be as obscure to Shakespeare's contemporaries who'd studied Latin from their school days and knew "caro, carnis" meant "fflessh of Man" like the back of their hand. That too is generously helped along by the contemporary Early Modern use of "carnation" to mean a pinkish-red color, the and the context clues that indicate Macbeth's talking about blood -- even if you can't parse out how "to incarnadine" is supposed to work as a verb, the image it's meant to evoke of making something a gory red is never far off. Even if you didn't understand the exact meaning of "to incarnadine", the scene is comprehensible; Shakespeare might then have been able to take a gamble on an Italian-derived word that gave him a kick and presented a pretty image rather than resort to a more commonplace phrase. Despite all his poetic complexities, Shakespeare wanted his plays to be understood as well as to be beautiful, and his love of novel words (whether or not they were his original coinages) doesn't seem to have gotten in the way of that goal.
Another wrinkle is that many of the hundreds of words given as "invented" by Shakespeare are attested in earlier writings. Shakespeare was a prominent user of these words, handy when it comes to drawing dictionary citations for the OED, but he wasn't their originator. Words like "to puke" may well have been in very broad circulation in speech and writing before Shakespeare immortalized them in the First Folio. (Even poor "eyeball" wasn't Shakespeare's original invention after all. I have led you astray.) This is a case of people turning to the OED for a citation of a word's attested occurrence and mistaking an early-ish, easy-to-decide-upon occurrence in Shakespeare for the earliest occurrence out there; in recent years it's become easier and easier to find attested uses of a word in searchable documents predating Shakespeare, rather than having to turn loose researchers on every library in the world scouring for a printed instance of "puke" or "eyeball" just to get a ballpark idea of when that word came into English-language use. It's a misunderstanding that's really easy to fall into and this misunderstanding further inflates the number of words attributed to Shakespeare as coiner of new words.
When people point to Shakespeare's usage of fresh words unused in previous plays, or the sheer number of distinct words in his plays, or his number of apparent coinages -- either as an abstract number (900,000 words! 400 new coinages! nay, 1000 new coinages! 1700 new coinages!) or in comparison with literary peers like Milton and Marlowe -- they're usually using this as evidence to support his genius. More is better in this argument, and a mathematical analysis of Shakespeare's language can therefore prove Shakespeare's genius. This doesn't really square for me. Shakespeare straight-up wrote more plays than Marlowe, on account of living some twenty years longer than Marlowe did, and he covered a wider range of subject matter than Milton. All these things add up to a superficially broader vocabulary, but do they really add up to anything else with any certainty? If prevailing literary opinion had spent hundreds of years building up Ben Jonson as the ne plus ultra of English-language literature instead of Shakespeare, I don't think there would be as many scholars citing Shakespeare's wordiness as a sign of Shakespeare's superiority, rather than a sign that Jonson's plays used language concisely and Shakespeare's plays were sloppily written monsters. (For the record, Jonson used plenty of neologisms himself.) This school of thought, and this way of calculating how many words Shakespeare supposedly invented, is a byproduct of 19th century Shakespeare scholarship's love of Bardolatry and the 21st century's love of trivia listicles rather than representing a genuine spike in altogether unfamiliar words single-handedly engineered by one man. If Shakespeare's plays are good, it's not their sheer volume of words that makes them good, and while his "new" words are pretty damn great, they likely weren't all that new to his contemporaries.
Some reading: