Why A is pronounced differently in "opacity" and "opaque"
Solution 1:
The root word and its derivatives don't share the same stress pattern, unless the latter is -ful, -ness, etc.
unique, boutique, technique, baroque, oblique, etc--all these words have a specific pattern.
V+que pattern:
- o+que > OH
- i+que > EE
- a+que > AY
VC+que pattern: you don't hear the above set of vowels in this case. Instead, you hear CAT, BOT, BET, BUT, BIT vowels, because the stressed syllable is closed.
In -ty pattern, the stress falls on the antipenult (third vowel from the right).
In 'opacity', the stress falls on the third from the right, which is 'a'. Since it is stressed, it attracts a coda consonant, making it a closed syllable.
o-PAC-i-ty: CAT Vowel, instead of GATE vowel in opaque.
Solution 2:
Neither of the above answers is really correct. The correct answer is that the variation in "opaque" ~ "opacity" (and many similar words, e.g. "divine" ~ "divinity", "serene" ~ "serenity", "profound" ~ "profundity"; also "wild" ~ "wilderness", etc.) is due to a sound change known as Trisyllabic laxing. This is well-explained in the Wikipedia article I just linked to. It also caused other variations like in "south" vs. "southern" -- at the time that this change happened, the latter word was actually "southerne", with three syllables.
Solution 3:
The answer is related to a linguistic process called Apophony, but I can't remember the exact term for this. However, the process is motivated by the syllables. Take a word like atom as an example. As we add morphemes to it, it changes the vowel quality: atom /ˈædəm/ -> atomic /əˈtɑmɪk/ -> atomicity /ætəmˈɪsɪti/.
edit: I should also add that the shift normally occurs around primary stress, which is why the O in opacity isn't changing.