Yokatta comes from the adjective 良い(yoi), 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”. Take for example this conversation:
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: Ostukaresama - "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 (よかった).
(I need some serious help here)