I’ve been trying to learn a new language (Vietnamese) and a thing that has been driving me crazy are all these instances of letters being randomly pronounced differently in different words sometimes. If you don’t think about it too much, it’s easy to go “this language is dumb, why do they do this?” But then I think about English and we have so many examples of this or other linguistic oddities that make no sense but which I’ve just accepted since I learned them so long ago.
So I wanted to generalize my question: For all the languages where this applies, why are there these cases where letters have inconsistent pronunciations? For cases where it sounds like another letter, why not just use that one? For cases where the letter or combination of letters creates a new sound not already covered by existing letters, why not make a new one? How did this happen? What is the history? Is there linguistic logic to it beyond these being quirks of how the languages historically developed?


Below is just one possible aspect of this, the other answers you’ve received are also valid. Writing systems are complicated!
Your making the mistake that writing systems are supposed to represent speech sounds. They do not (or at least they don’t have to). As an example, in my accent (midwestern American English) there are at least three different sounds I make for “t”:
These are the technical names linguists use for these sounds; you can find them on Wikipedia if you want to know more. English speakers can agree though that they are all “the same thing”; the technical terminology is that they are all allophones of the same phoneme. Different accents will have different allophones, for example some English accents may pronounce this “t” phoneme in “matter” and “mat” the same way as my “touch”. If you think this is splitting hairs, that’s just false; the way languages divide sounds into phonemes varies greatly. For example, Japanese speakers consider my “touch” “t” and my “matter” “t” to be two completely different sounds, i.e. two different phonemes which are not interchangeable.
(Very) roughly speaking, writing systems tend to map better onto phonemes than onto actual sounds. Part of your frustration with Vietnamese writing could partly be from this: Vietnamese possibly has some sounds as allophones which in English are not allophones and belong to different phonemes. In other words, to a Vietnamese speaker they are the same sound.
One more example is the Cot-Caught merger present in some varieties of English. In my accent, the vowels in these words are two separate sounds for two separate phonemes. In English accents which have the merger, they have become the same phoneme and in fact are pronounced identically, with the exact sound depending on the particular variety of English.
This shows one way you can end up with different spellings for identically-pronounced words.