Yokatta comes from the adjective いい(ii), meaning “good”. It is this adjective’s past conjugation, 良かった (yokatta). In other words, “yokatta” literally means “was good”.
However, in Japanese “yokatta” is often used as an interjection that can be translated as “I’m so glad”.
Now, how could “was good” mean something like “I’m so glad” in Japanese?
The thing is, a lot of Japanese culture includes simply stating what you see.
For example: Otsukaresama - "You're tired!"
Oyasumi - "You sleep!"
Ohayou - "It's early!"
Kawaii - "Cute!" Oishii - "Tasty!"
A lot of conversations have this kind of stuff too... Almost like one person tells a story, and the other person just describes their feelings about what they're hearing.
Anyway, usually when someone explains something good that happened, the other person will say "Yokatta!" just to point out that it's good news for them, or (if it's better news for the other person) to show they're listening and taking an interest in what's being said.
By the way, “yokatta”, when used as an interjection, is usually written only in hiragana (よかった).
Here are two examples of よかった in a sentence. In each example, the word is the same, but the nuance is changed due to the nature of the sentence- and that is made clear by the translation:
東京はとてもよかったです / Tokyo was great. (The general use: "was good")
A: 犬が買えました。名前はジムです。/ I was able to buy a dog. His name is "Jim" B: よかったですね。 I'm glad to hear it
The second example shows the interjection form of Yokatta in contrast.