Short answer: English spelling does not display a one-to-one correspondence with pronunciation, and certainly not with modern pronunciation. You shouldn't expect it to.
Medium answer: These words are spelled with the same letter combination but pronounced with different sounds due to a combination of different etymologies, and different sound changes. Some of them started out with different pronunciations and stayed different; some of them started out with the same pronunciations and diverged over time.
Long answer: In some cases, the modern spelling never corresponded to the word's pronunciation and was only established by analogy with other words with a similar meaning. This is the case for "hiccough": the word is not actually derived from cough. But people started spelling it with -ough because they thought it seemed similar to cough. There are many other words that exhibit this phenomenon: island (never pronounced with an s), scissors (with extraneous s; it comes from the root cis-) foreign (never pronounced with g), ptarmigan (never pronounced with p). Another oddity is the word furlough, which comes from Dutch verlof; I have no idea why it changed pronunciation and spelling.
However, most words spelled with gh did originally have a corresponding consonant sound in this position: a velar fricative /x/ (which can still be seen in related words in some other languages, as Roger Mue's answer shows). The spelling gh was one of the usual ways of representing this sound in Middle English. The words are pronounced differently now because they underwent sound changes. In all languages, words change in pronunciation over time. In some words, the sound /x/ changed to /f/ (see this question to learn why: Why did /x/ change to /f/ in English?), while in others it was dropped, but caused the previous vowel to become a diphthong. This particular sound change only applied sporadically, so the sounds in some words shifted one way while in others they shifted a different way. The vowels also changed in various ways, sometimes irregularly.
To try to see if there were any regular patterns, I divided the words into several "classes" based on how they are pronounced.
I'll use the abbreviation "OE" to stand for "Old English" and "ME" to stand for Middle English. Be aware that the historical forms I list are not comprehensive. The forms are taken from the Oxford English Dictionary (OED), New Oxford American Dictionary, and Wiktionary. The words on the left have an arrow < pointing to them to show that they descend from the words on the right. Words preceded by an asterisk are hypothetical/reconstructed rather than attested forms.
ough = "aw" (very nearly, all words and only words with ought):
- thought < OE þōht
- sought < OE sōhte
- bought < OE bohte
- nought < OE nowuht
- wrought < OE wroht
- ought < OE āhtan
- fought < OE feaht/fuhte/fohten
- daughter (variants dofter, dafter) < OE dohtor
(I know "daughter" isn't spelled with ough, but it has a similar history and the same pronunciation.) It's unclear to me why the pronunciation developed this way in these words, but it seems quite regular. The one exception I've been able to find, drought, can be explained if we look at the history: it comes from Old English drūgað, which unlike all of the other ought words, had the long "ū" vowel. This long "ū" came to be spelled "ou/ow" in the Middle English period by historical accident. (More on that here: Why does “ow” have two different sounds?).
ough = "off":
- cough < OE *cohhian
- trough < OE trog/troh
These two words have the normal “short o” vowel. This makes sense because they both had a short "o" in old English, although it was pronounced differently from how it is now (it was literally a shorter version of the long ō sound). However, there are not enough ough words with this pronunciation in Modern English to say if the development was "regular" or not. They also show the change of [x] > /f/.
ough = "ow" as in cow:
- bough < OE bōg/bōh
- plough/plow < OE *plōg/plōh
- enow < OE genōg/genōh
- slough (n) < OE slōg/slōh
These words all had long "ō" in Old English. Normally, this developed to an "oo" sound (as in goose), but it seems to have followed a different path in these words. It seems that it joined with long "ū" in Middle English, and then developed to the diphthong that is currently present (Eilert Ekwall, ed. 1907, Dr John Jones's Practical Phonography (1701)). (One possible exception is slough, which is often pronounced as sloo/slew.) I think we could compare this to the development of some Old English /e/ or /ea/ followed by /g/ or /x/ to late Middle English long "ī," as in the words "eye" and "die." (And interestingly, this change also was sporadic: compare the pronunciations of "eight" and "height.")
Another significant fact is that all of the above words had variants with g instead of h in inflected forms, such as the plurals; and in fact the now-archaic enow was used as the plural form of enough. For this reason, several authors say that these forms actually derive from Old English forms with g rather than with [x] (Wyld 1907).
ough = "oe" in toe:
- thorough < ME þorwe among other forms < OE þurh
borough < ME burwe among other forms < OE burg/burh
I would guess these developed similarly to words like furrow (from ME forwe among other forms < OE furh), arrow (from OE earh/arwe), and sparrow (from OE spearwa). That is, the final h or g was replaced with the semivowel w, which subsequently developed into an oaw sound. For some speakers, the current pronunciation has developed further to a schwa sound /ə/.
dough < OE dāh
This word had long "ā" in Old English. Normally, this developed to an "o/oa/oe" sound in Modern English (as in cold, stone or toe) and this seems to have occurred here as well, as least for the standard pronunciation. One dialectal pronunciation is discussed further down.
though < Old Norse *þōh
This is another word that shows several phonetic variants in different dialects. The Oxford English Dictionary gives the following explanation:
Old Norse *þóh (intermediate to þauh and þó), [was] shortened
in Ormin to þŏhh, with subseq. stress-lengthening to þōuȝ, though,
thō. The Norse form gradually gained over [the Old English forms], which
disappeared from literature before 1500. [Other] forms show the same
development of f < ȝ, gh /x/, as in laugh, cough, tough; thof
was occasional in literature as late as 1750, and is still prevalent
in many varieties from Yorkshire and Lancashire to Hampshire and
Devon: see Wright Eng. Dial. Gram. In Scotl. and north of Engl.
though is pronounced /θɔː/; the Hampshire and West Somerset thof also is /θɔf/, not /ðɔf/.
ough = "uff":
- duff (variant pronunciation listed by the OED for "dough") < OE dāh
- enough < OE genōg/genōh
- tough < OE tōh
- rough < OE rūh
- slough (v) (uncertain origin)
- chough (precise ancestor of this phonetic form unclear)
This set appears to be the most heterogeneous. They all show the shift of the consonant [x] to /f/. In addition, it appears that the vowels in these words underwent two processes before this consonant: shortening and a change of vowel quality (perhaps not in that order). Duff and enough both have alternative pronunciations descended from the same origin, which seems to indicate that there is no way to tell from the word's etymology that it will be pronounced with "uff."
ough = "oo":
- through < OE þurh
- slough (n) (some varieties)
According to the OED, the vowel sound used for ough in through is the result of re-stressing a vowel that had become unstressed (the word originated as an unstressed version of thorough). There are other examples of this sort of thing in English: the re-stressed "ay" /eɪ/ is used as a strong form of the indefinite article "a," which originated as an unstressed version of the numeral "one"; the re-stressed "ov" /ɒv/ (in British Englis) or "uv" /ʌv/ (in American English) is used as the strong form of the preposition of, which originated as an unstressed version of the preposition off.
There is also some variation between these pronunciations for several words.
- Henry Cecil Wyld, 1907, The Growth of English: An Elementary Account of the Present Form of Our Language, and its Development, by Henry Cecil Wyld
- William Labov, "Regular Sound Change in English Dialect Geography," in History of Englishes: New Methods and Interpretations in Historical Linguistics, 1992, edited by Matti Rissanen, Ossi Ihalainen, Terttu Nevalainen, Irma Taavitsainen