The mishnah before us, chapter 5 mishnah 6, deals with the question of how to treat wine vessels in a city where soldiers who worship idols were stationed. The discussion must be divided into two separate cases: a time of peace and a time of war.
The first case - quartering soldiers in a time of peace:
Quartering soldiers was an ancient practice, going back as far as the world was created, in which the local population was expected to supply food and lodging to the soldiers of the local army. This was one of the central grievances of the Americans in the American Revolution against the British soldiers, and it even led to an amendment in the United States Constitution - the Third Amendment - forbidding this practice under ordinary circumstances.
Since the local population is expected to supply the soldiers with their needs, the soldiers assume they are entitled to help themselves. Therefore, if the question is whether we should be concerned that soldiers quartered in the city touched the wine, took some of it, or drank from the wine supply - the answer is certainly yes, because they feel at home. On the other hand, there is no reason to assume that they would do so secretly and try to conceal their access to the wine, as we saw in the previous mishnah.
From here there are three situations:
Open barrels - we must assume that the soldiers touched the entire open wine supply or took from it, and therefore all of it is forbidden.
Sealed barrels - permitted, since it is not their way to reseal the vessel in order to hide what they did.
Vessels with a lid or a stopper that can be replaced - forbidden like an open barrel, since it is a person's way to drink from the bottle and put the stopper back in place.
In the words of the mishnah:
The mishnah uses the term "boleshes," which literally means a band of searchers. "Livlosh" in Aramaic is the translation of "to search" and to seek out something, and even in modern Hebrew a "balash" is a detective. Soldiers who worship idols are considered a boleshes: they are searching for plunder and take for themselves whatever they can and whatever they want.
"Boleshes shenichnesah la'ir bish'as shalom - chavios pesuchos asuros, sesumos mutaros" - if the soldiers entered the city in a time of peace, and this is merely a matter of quartering them, all the open wine barrels in the city are considered as though the soldiers touched them or drank from them, and therefore they are all forbidden; but the tightly sealed barrels are permitted, because there is no reason to assume that they would try to hide what they did.
The second case - a time of war:
In a time of war, the soldiers passing through the city are in a hurry and do not linger, since they fear for their lives and are liable to be killed. Therefore "bish'as milchamah - eilu va'eilu mutaros, lefi she'ein pnai lenasech" - all the wine vessels are permitted, both open and sealed, because we assume they had no free time to occupy themselves with the wine and pour it as a libation. They pass through the city, grab whatever appeals to them and take it along; but to linger over the wine, to drink from it and play with it - that is not a concern.
It should of course be said that if the vessels were sealed before the soldiers entered and were found open after they left, this is proof that they touched them, and that wine is forbidden. But any wine for which there is no proof that they touched it - we assume they did not touch it, since these soldiers have no free time to occupy themselves with such things in the middle of a war.
In summary: Our Mishnah draws a distinction between soldiers stationed in a city in peacetime, who feel at home there and openly help themselves - and therefore any wine that is open, or merely covered with a stopper, is forbidden, and only sealed wine is permitted; and soldiers passing through in wartime, who have no leisure to pour libations, and therefore everything is permitted, unless there is clear evidence that they touched the wine.