Presumably the origin of war lies in the human habit of thinking of groups of humans they do not belong to as the other.
When humans gave up hunter gathering and began to acquire more property than they could carry and see land as an asset to be owned, then they had to fear the other coming and taking away what they had as well as to covet what the other had.
When there was a sufficient surplus of production there was room for a glorified protection racket, with a strongman offering to train professional soldiers to defend against the other. Getting retaliation in first is also an old human habit. So things build to our present state.
Wars can only be fought when there is a surplus of resources to support those doing the fighting. I am not sure however that the particular economic system which produces that surplus is the critical factor.
It is indeed difficult to talk about functionality of war within capitalism when the phenomenon of war is so much older. Empirically speaking, capitalism(s) do not know all own working options well as yet. The modern war does seem to function for certain industrial-political elites in the US in somewhat familiar ways - but that does not necessarily mean that war is playing a role for the capitalism. Rather contrarily, the system that Republican elites is striving for looks more like unbounded feudalism (for the few able reap everythig around). Their basic instinct is preservation of their wealth and status through generations, and they do it in the most straightforward "tried" way - by limiting de facto possibilities for those still behind, and allowing themselves absolute "freedom". Here warfare indeed works in familiar ways for them. (In fact, freedom of warfare might be considered as one of their traditional freedoms, ha ha.) Somehow they (almost) manage to achieve feudal standings within the modern frames of democracy and even (yes!) capitalism.
But you seem to conflate massacres with warfare and that makes what you say false.
In particular, you assume that hunter-gatherers did not engage in massacres, which is false.
You also assume that demonization of others is a cause of bloodletting rather than an integral aspect which is in need of explanation.