In peace time people invent things for peace and for war, in war time the focus is all on inventing things for war. Screw everything else.
Later on, after the war is over, it may turn out many of the things that were invented for war may also have uses for peace, this however is perhaps not always the case. I don't think the inventions of the first world war that spring first to my mind had a lot of utility beyond war.
The second obvious reason why peace would be a necessary ingredient is the cause of all that inventiveness around creating things for war, it's because in war you are in danger all the time of being killed, which is why when you are not hiding somewhere trying not to be killed you are trying to make things to kill the other guy because if you kill the other guy they can't kill you. If you get killed however, that will be a big dampener on your ingenuity.
Some people might think differently about this state of war, because of historical blindness and the inefficiencies of the English language. If a country is big and powerful enough it can go to war elsewhere, and never have the war touch it.
This is not really war as it has been known in most of the history of humanity, but we call it war. It is really a time of peace in the homeland, and distributed external war.
And in this time of peace in the homeland, people can work peacefully without fear of being killed, and then people who think that this is war say - hey, check it out, peace is not needed for invention and progress at all!
It's probably a bit of both, IMO. I don't doubt that pressure and threats to survival can also make people snap out of ruts they have been in, and look for something beyond what they already know. But I still would say you can have inventions without war, but you cannot have them when there is nothing but war. And my argument would be that the extreme of that would be someone who gets screamed at and beaten from the moment they were born, and lives in constant state of war. They will not be able to find the rest and perspective to invent things, they may not even survive.
Think about it. Math is a hobby, practically useless. But it benefited humanity with side effects like engineering and computers.
Now to your point. Because math is initially a pretty useless endeavor it can only arise as a leisure hobby. A leisure hobby can only arise in people who have tons of leisure time and have no need to fight for survival. Thats why peace time is important.