Though keep in mind that it might be states being at war with each other, it's usually (but not always) individuals or companies that are trading.
The interests almost never align.
The country as its citizens does not profit from war. The country as its leaders sometimes it does, or at least it may do so in the short term.
With the government of the day making exceptions as they feel fit
When they do: https://en.wikipedia.org/wiki/Corporatocracy
But it's much more than that I think: when the stuff you sell to the other side can easily be substituted, from another supplier, domestically or by changing to ways that get by without, where's the benefit of stopping trade? Those 0.5% the other supplier has been more expensive (if it even is, might very well have just been inertia keeping them buying from you) won't meaningfully harm their war effort.