Themes are a difficult concept to pin down, but I think the definition is something close to "an area of the human psyche that is central throughout the story". Every story should have one, and preferably just one. A well-executed theme is something the story can be said to be "about". I'll give some examples to illustrate my theories about the concept.
The theme of my novel Pillars of Life is courage. The protagonist's arc is about learning courage and it's a frequent topic of discussion and thought for the characters. I don't think I did a very good job portraying fear or exploring the thoughts that go through a mind that know they're in danger, but it was something you could probably say the story is "about".
Within the broader theme of courage, it touches on at least two sub-themes. The first is prudence. Courage is often contrasted with prudence, and this tension comes up multiple times in the story. Instead of being all the way biased, I make the characters within team good disagree about it sometimes, and don't always clearly choose a side. The story definitely favors courage (and intentionally so), but not always, and I do regret how I handled the chapter 4 instance.
It also touches on the idea of what you might call "axiological defiance": maybe sometimes it's morally right to be brave even when it's strategically unwise, simply because submission is morally undesirable. This idea is referenced in said chapter 4 instance when Mitilda explains to Gabriel in chapter 4 that she knows her plan to steal food from the government is far riskier than it is rewarding, but she still intends to do it, and she is portrayed as right. I genuinely agree there is value in that. Sometimes the moral value of Agency combined with the time-preference principle outweigh prudence.
Another example I'll talk about is the first Mistborn trilogy, especially the first book. This story has two major themes: hope against impossible odds, and trust, as opposed to cynicism. Hope is the external, ostensible theme that would be preserved in a plot summary, while trust is the internal theme that's the center of Vin's arc. Most of the time having more than one major theme is bad for a story because they draw attention away from each other, but in Mistborn, due to the contrast in the roles they fill, these two themes don't clash.
The Pygon Hybrid (a novel I abandoned) was supposed to be about how Telra's ideology (which I somtimes call prodigalism) leads to Protagonism. Her highest values are "strength", "dignity", and self-respect, and she doesn't assign any real value to anyone she considers "weak". But, being a morally good person in all ways is harder than not, so when confronted with good people who show her that compassion is not weak, prodigalism ceases to be internally consistent, and so Telra would've gone on to become more of a moralist.
Doki Doki Literature Club is a story about repentance and forgiveness. The plot culminates in finding out who murdered the other girls, and spends the little duration it has left making her seem forgivable, and for extra effect, it ends showing one of the characters you probably thought most innocent following the same path in the same situation. By the end, most players don't see Monika as a villain, because she isn't. This is a very well-executed theme.
For some examples of failure, let's discuss certain AAA video games. First up, Mass Effect.
Mass Effect 1 doesn't have much of a theme. In the beginning, it seems like it's about "humanity finding a place in a galaxy of more advanced and more experienced alien races". But that theme kind of gets dropped. Nobody ever mentions it again until the end of the game, where suddenly humans are the heroes for saving the Citadel from Sovereign and everyone looks up to us now. And in future Mass Effect games they just soft-retcon that ending and go back to the galaxy not trusting Shepard and the human councilor not having any power, and completely ignore the theme.
But in the encounter on Virmire where Saren reveals his motives and they're actually pretty interesting (and, most interestingly, it is the reasoning of a minarchist), it seems like the game might pick up the entirely new theme of Pillars of Life's idea of defiance as mentioned above: the Reapers are coming and we're hopelessly outmatched, but it's still wrong to give up and willingly submit to them! We have to try! That theme also isn't referenced again, until vaguely at the final scene, where it's distracting from the resolution to the original theme. The point is, Mass Effect's lack of a clear and consistent theme was a mark against the story. It was still fun because the story was strong in other areas, and looked very promising for the sequels. Also the combat was fun no matter how bad the story might have been.
What I'd have done is take the theme of defiance referenced in the Saren conversation and make that the main theme of the story. It would be foreshadowed early in the game (perhaps with a situation that was sort of a microcosm of the issue), and then it would be even more satisfying when Saren revealed that.
Mass Effect Andromeda went a completely different direction. In the beginning they sell the theme of "exploring a new land and finding a home". Unlike the previous games, this theme is at least consistent. It's there all throughout the game and one of Ryder's final lines can be (asked what the Nexus should be told) "Tell them we're home". This is an improvement. The only reason I didn't like it a lot more was because that particular theme just doesn't resonate with me. Themes are a very person-relative thing and that's part of why two good people with the same philosophy on storytelling can disagree on which story is better. The idea of 'home' just doesn't have any emotional significance to me (in fact it kind of has negative significance due to reactance bias).
Next up: Assassin's Creed. The first game in this series has even less of a theme than Mass Effect 1. The only semblance of one you have is the exploration of the Templars' true ideology (world peace through control), which isn't really fleshed out until much later in the series. Desmond or Altair never confronts this idea on a philosophical level or even acknowledges its legitimacy (which I think is fine since it's pretty disgusting to me but weird since the entire audience lives by this philosophy in real life - it's the communism hypocrisy all over again!). In later games, such as Assassin's Creed 3, they finally have a Templar be more of a character and they do a good job of showing how someone doesn't have to be completely evil to believe this. Haytham Kenway is introduced as a hero liberating kidnapped native Americans, and his behavior is so heroic that the audience is convinced he's an Assassin. The striking thing is that even in hindsight nothing he did contradicts his Templar ideology. He freed the natives because the British soldiers capturing them weren't doing it for anyone's safety but to advance their own violent colonization of someone else's home. I admire what they aimed for in AC3. But they kind of shot themselves in the foot. They showed how their enemy's ideology isn't pure evil by showing a heroic character who believes it, but they still didn't contend with it intellectually. The audience is still supposed to take it on faith that the Templars are unilaterally the badguys and for some reason, everyone does.
The same thing happened with Star Wars. There's some trick to storytelling that allows you to work in morals most people would be disgusted with if you spelled them out but somehow everyone cheers them on. I haven't figured it out, but when I do, I'm going to exploit the shit out of it.
So I hope that was insightful. Next time you're planning a story, I encourage you to ask yourself what the theme is, and decide on an answer before you get too far into the process.