My hypothesis. Party A wants Thing from party B. Moreover, party A things they could take it by force. Even if party B things they couldn't defend Thing, they can't just give it, because that sets a wrong precedent. Party B relies on being able to exact a very high toll should party A try to get thing.
Rationally, you don't declare a war you don't expect to win. So, in the above scenario, when part A declares war, they expect that party B cannot exact a high enough toll for Thing. When they do, it was a mistake.
The alternative are wars for 'moral' reasons, which are mostly about retribution or saving face. This is essentially how the murder of a prince lead escalated to a war that became WW1.