The first way is that you've been to articulate clear goals, have been able to string together methods and means that at least on paper allow you to reach those goals, have been able to secure the relevant support (so national/popular will, backing of an aristocratic class, etc etc) to see through the task, and then come up short. For a classic example of this, we can look at WW1 Germany. Despite everything we know about how the war ended up, there was a path (but treacherous) to the Central Powers achieving their goals and being able to set the terms at the end of the war.
The second level is that you've failed one or more of the above tasks. In which case you're likelihood is losing gets much higher, possibly to the point where future historians might look back and say that you've lost before you even started. For classic examples of this, you would look at WW2 Japan and Pearl Harbor. It is incredibly difficult to find any analysis that didn't require continuous strings of miracles for Japan to achieve its aims once it had attacked the United States. Note that the second case consists mostly of a lot of "non-military" things.
Another thing that may help you out in your quest is to grasp of some of those is to understanding the three tier organization of tactics, operations and strategy. In fact, I can point you right back to one the author's blog series (this is part one of a six part series) where he analyzes the siege of gondor (yes LOTR) from a realistic-ish point of view (https://acoup.blog/2019/05/10/collections-the-siege-of-gondo...).
It'll probably start to give you a feel for maybe how you could rephrase your original question into forms that'll more likely give you the types of answers that you'd be satisfied with.
This is a whole field of political science.
> Things like not planning for muddy terrain contributing to a battle being lost
That really has nothing to do with how wars are won and lost. Wars are won or lost when the politicians or depending how you look at it society at large stops fighting.
A muddy terrain might be a tactical consideration that could help you win one battle, or campaign and that you can then maybe leverage into something you could then call a victory. In every war millions of mistakes are being made, pointing to 1 of them and assigning and extra ordinary relevance to it, is very difficult.
What I can tell you is that there is no universal answer neither in political science, nor economics, nor military theory. In fact, this very question has baffled military theorists for literally 1000s of years.
The most popular reference is from Carl Von Clausewitz, a Prussian military theorist, he claimed you have to identify the 'center of gravity' and and then do what is in your power to shift that.
> The definition of a CoG is "the source of power that provides moral or physical strength, freedom of action, or will to act."[2] Thus, the center of gravity is usually seen as the "source of strength".
Of course you will notice that this is incredibly vague and provides little practical guidance.
This is the difference between historians, who try to find the end of individual wars, and military theorist and political scientist who try find more abstract descriptions.
You can read something like 'Strategy: A History' to get a general overview of how people have thought about it.
I highly recommend going to reddit.com/r/AskHistorians. They have a great wiki and reading list, or you can ask for books.
If you are interested in more ancient history, I can warmly recommend Keagan's Peloponnesian War (which mostly draws on Thucydides eponymous masterwork).
1 - Book: A Bridge Too Far - until Cornelius Ryan wrote the book in 1974, operation Market Garden (WWII) was regarded with somewhat muted, neutral or positive outcome, the kind political leadership wanted to bury and did for decades. But his book detailed just how horribly disastrous it went and how out of touch commanders ended up being in their planning, tying confidence to their egos. An example of one thing that went wrong, they landed some 35,000 paratroopers in the operation and the British group's radios had an effective range of 3 miles, but the groups that needed to talk to each other were landed 8 miles apart. Another part of the plan called for a group to head down a road to join another contingent for the next step, but didn't accurately estimate the road's capacity or how clogged it would get and how long it would take for them to make it - which ended up being 3x+ times as long, obviating their combat role.
Takeaway: that muddy terrain thing you mentioned is pretty important. Also, a realistic sequence of events.
2 - twenty year-old commentary: a retired colonel's reflection on Arab militaries and ineffectiveness of military advisors/trainers in Arab countries. http://americandiplomacy.web.unc.edu/2000/12/why-arabs-lose-...
Takeaway: western countries keep ignoring cultural differences, sending off military instructors and advisors in waves after waves and expecting a particular unrealistic outcome from the effort.
3 - find your own rabbit hole on various information and writeups about all-women antiaircraft teams in WWII. Short version, British women could do maintenance, spotlighting, loading and aiming but were not allowed to pull the trigger because only men were allowed to shoot at other men. By contrast, Russian AA all-women teams were allowed to. Here's a starting point that just barely touches on this very-fascinating subject and shows how wide it is - https://www.iwm.org.uk/history/the-vital-role-of-women-in-th...
Takeaway: German pilots had their opinion of the matter, and they much preferred the British solution.