Why do in a lot of wars you see where a nation has a "better" army and generals and they still lose the war. Why is that?
Well if they loose they clearly dont have a better army and/or generals.
Like madviking said, luck has an awful lot to do with it. Warfare is one of the most contingent human activities, and relatively minor occurrences that have little to do with the overall quality of an army can have massive rippling consequences.
In addition, in almost all cases, the alleged superiority of one army over another is overstated dramatically. Certain armies are usually incrementally better, in institutional terms, than other armies in doing certain things. That's generally balanced out by the other army having its own advantages. Rarely, if ever, will you see a fighting force that is extremely good at ALL THE THINGS, and has every single possible advantage over an enemy force.
So in that sense, warfare is about maximizing your army's own advantages and minimizing the opportunities for the enemy to bring theirs into play. But, again, in most cases, those advantages are very incremental. The Spanish armies of Fernando VII that tried to reconquer the New World from the rebellions of Sucre, Bolivar, and the rest weren't
that much better trained and armed than their opponents even at their best, and frequently they were not at their best. Russia's forces rarely had That Much of an advantage over Ottoman ones in terms of leadership, discipline, and technology. That sort of thing.
It's fairly rare to see a situation like that of the Roman military against the so-called "barbarians" on its frontiers, or the Spanish armies against the indigenous population of the Americas, in which the advantages held by the one side are so massive as to render the other side's victory highly unlikely, sometimes to the point of near impossibility. Even in those encounters, though, the role of the commander, of tactical maneuver, of nonbattle military operations, retained enough force and meaning to permit either side to potentially win the battle. Supposedly, the Triple Alliance forces that confronted Cortes at Otumba could have blockaded the Spanish and forced them to surrender quite handily instead of risking everything on a set-piece battle that went the wrong way. (Guy Halsall has described battle as being, in many contexts, a lottery, regardless of the strength of certain armies at certain things. It's not an uncommon sentiment, but I like the way he puts it. In addition to being a historian, he's also a pretty good tabletop wargamer, so he's thought about this sort of thing an awful lot.) And Roman forces sometimes
did lose to "barbarians", although it was a fairly rare occurrence.
So, to answer your question, "better" doesn't usually mean what you think it means. And even armies that are institutionally superior in some respects cannot overcome other factors, especially ones related to luck, in all circumstances. It's not like a video game, say
Advance Wars, where certain armies (e.g. Colin, Kanbei) can take advantage of super-cheese institutional advantages that overwhelm anything any other army can bring to bear.
It brings to mind certain battles in the American Civil War, which the Union won despite loosing several times more soldiers than the Confederate armies was able to field in the first place.
This is a massive exaggeration.
Victory in any sort of warfare is fundamentally, as Nathan Bedford Forrest put it, about getting there fastest with the mostest. It's about having more firepower in contested territory than the enemy - not necessarily about being the stronger force.
This is mostly right.
Premodern - i.e. "before the Second World War or so", and arguably even after that - warfare did not revolve around killing large numbers of enemy troops. Obviously, an army
wanted to do this as much as was possible and non-risky. But killing enemy forces was not the best way to win a battle: forcing them to retreat
was. Most battles in history don't feature a casualty rate higher than thirty percent on either side, and thirty percent casualties are usually considered to leave a given formation gutted. That means the majority of soldiers, even in the worst defeats, retreat and survive the battle. Armies wanted to force the other side to retreat and yield them their immediate objectives, not to slaughter every enemy soldier - especially since killing enemy troops generally means putting your own men at risk.
Before the late nineteenth century or so, though, this usually
did go hand in hand with high casualties. Until the introduction of modern breech-loading and bolt action firearms, the mere act of fighting itself was enough to occupy a given soldier's attention. Whether the soldier was wielding a spear and shield in close combat or firing and reloading a smoothbore in line formation, he was generally so occupied with what he was doing at the time that he didn't really have much situational awareness, or time to think about what, exactly, was going on. This started to change as the battlefield got "emptier" and the act of fighting became
physically less absorbing. Soldiers had the opportunity to think about was going on during the fighting, frequently spent time alone or in very small groups instead of large formations, and in general had to deal with more psychological pressure than did their earlier peers.
At the same time, of course, battles opened up massively in terms of scale, both geographically and numerically. In addition, warfare became a more continuous exercise, arguably starting with the Overland Campaign in the American Civil War. (A notion that was developed pretty well in Gordon Rhea's books on the campaign, especially
To the North Anna.) Before, the overwhelming amount of military operations were short, sharp, and vicious, but not prolonged. A Cannae or a Malplaquet would see thousands dead on the field in a few hours, but relative inactivity for weeks and months on either side. (By comparison, even the Federal assault at Cold Harbor, in which eight thousand men allegedly died within half an hour, would be peanuts. Of course, those figures were made up by Humphreys to discredit Grant...) In the Overland Campaign, though, the Federal armies continued to push, fight, and march after basically every battle. The act of battle itself became less important than the sort of maneuvers it allowed the army to undertake leading to the next engagement. This wasn't true operational thinking, because Grant and Meade still considered battle to be the way in which they would destroy the Confederate army force-on-force for much of the campaign, but it was something like it. And it meant that the soldiers on both sides were forced to endure further marches and repeated encounters over the course of the following months. From the Battle of the Wilderness to Cold Harbor, the Army of the Potomac and the Army of Northern Virginia were engaged in more or less constant fighting and marching for six weeks. By the end of it, both forces were nearly tapped out as effective fighting forces, something that would probably have forced a lull in the fighting just as surely as Baldy Smith's failure to seize Petersburg did. And, of course, European armies were able to experience this as well, in the Battles of the Frontiers at the opening of the First World War.
That's not to say that the tropes of modern warfare - that it involves about 99% inaction, boredom, and waiting and 1% fighting and terror, for instance - aren't true. (My personal favorite one is that there are two elements of war, mud and dust.) But they were even
more true earlier in history. No country on Earth could sustain operations at the tempo of the Overland Campaign, the Battles of the Frontiers, or even the 1991 "hundred hour war" in the Gulf, for a decade, much less eighty years as in the case of the Dutch. Nobody could, really; in the aftermath of those big campaigns in the great industrialized wars of the last century and a half, armies had to stop and institute general operational pauses. There are limits to what men can do in war.
This was a kind of meandering, rambling answer to a question that wasn't really asked, but I think it's reasonably relevant and there are some useful nuggets in there.