Can't find any official rules about holding breath in combat in 5e. If there's a poisoned gas in the room, and party is fighting against some creature with poison immunity, like golem, and so this golem smashes one of PC's hard - do this player need to roll something not to lose his breath? It is quite normal in real life to blew all what you've got in your lungs once you get punched. What do you think?
Check out the Suffocating rules
The rules on suffocating can be found in chapter 8 of the PHB, or just in the basic rules such as on D&DBeyond:
A creature can hold its breath for a number of minutes equal to 1 + its Constitution modifier (minimum of 30 seconds).
When a creature runs out of breath or is choking, it can survive for a number of rounds equal to its Constitution modifier (minimum of 1 round). At the start of its next turn, it drops to 0 hit points and is dying, and it can't regain hit points or be stabilized until it can breathe again.
For example, a creature with a Constitution of 14 can hold its breath for 3 minutes. If it starts suffocating, it has 2 rounds to reach air before it drops to 0 hit points.
In your case, the DM can make a ruling
However, the above does not cover your specific situation. If you take damage whilst holding your breath, the rules are silent on whether the creature damaged should suffer any penalty with regards to holding their breath.
One of D&D 5e's mantras is "rulings, not rules", and this is one such case for that. As a DM (I'm assuming you're the DM in this scenario?), you could come up with a ruling for this situation; I would suggest something like a CON save with some penalty for failing, such as losing 30 seconds worth of holding your breath, or even just "you aren't holding your breath anymore". But such a ruling at that point would be something the DM would come up with on-the-fly (although, once such a ruling has been made, it's best to be consistent with it henceforth in the interests of fairness).
Holding your breath may not be a useful strategy against poison
@NathanS's answer covers the suffocation rules that seem very applicable to this situation, but I wanted to cover whether holding your breath is an effective strategy.
Your example of the golem
In your question, you state:
party is fighting against some creature with poison immunity, like golem
Looking at the golems with poison breath, that suggests you are discussing the Iron Golem.
The Iron Golem's Poison Breath (emphasis mine):
The golem exhales poisonous gas in a 15-foot cone. Each creature in that area must make a DC 19 Constitution saving throw, taking 45 (10d8) poison damage on a failed save, or half as much damage on a successful one.
The effect works on each creature in the area. It doesn't say that it targets each creature breathing, but just each creature. A DM can always rule how they'd like, but RAW, the effect works against any creature. Poison gas doesn't necessarily have to be inhaled in order to work - it can absolutely enter through other means.
Poison/gas effects in general
If the effect doesn't specify "creatures that can breath", then generally it works whether breathing or not.
As I said before, if a DM wants to rule that you need to breathe in order to be affected, that's totally fine.
Most importantly, the Basic Rules covers the different types of poison and notes that holding your breath against the inhaled variety is not effective:
Inhaled. These poisons are powders or gases that take effect when inhaled. Blowing the powder or releasing the gas subjects creatures in a 5-foot cube to its effect. The resulting cloud dissipates immediately afterward. Holding one's breath is ineffective against inhaled poisons, as they affect nasal membranes, tear ducts, and other parts of the body.
The other poison types are contact, ingested, and injury - none of which would holding your breath be an effective way to avoid their effects.
The curious case of cloudkill
It does get a little squirrely with things like cloudkill which states:
When a creature enters the spell's area for the first time on a turn or starts its turn there, that creature must make a Constitution saving throw. The creature takes 5d8 poison damage on a failed save, or half as much damage on a successful one. Creatures are affected even if they hold their breath or don't need to breathe.
This line suggests that other things may allow you to hold your breath and I'm really not sure why they needed to state that. Given that, it is absolutely plausible for a DM to rule in other cases that you can hold your breath.