Step 1: Understand the concept
Solubility of a gas in water depends on how well the gas interacts with water molecules. Polar gases, and gases that react with water, dissolve far better than non-polar gases.
Step 2: Check HCl
HCl is polar and reacts with water to give \(\text{H}_3\text{O}^+\) and \(\text{Cl}^-\). It is extremely soluble, about 450 volumes in one volume of water.
Step 3: Check \(\text{NH}_3\) and \(\text{CO}_2\)
\(\text{NH}_3\) forms hydrogen bonds with water and gives \(\text{NH}_4^+\) and \(\text{OH}^-\), so it is highly soluble (about 700 volumes). \(\text{CO}_2\) reacts partly to give carbonic acid and dissolves about one volume per volume of water.
Step 4: Check \(\text{O}_2\)
\(\text{O}_2\) is non-polar, forms no hydrogen bonds and does not react. Only about 0.03 volume dissolves per volume of water. This is the smallest value, so it is the least soluble.
Final Answer:
Oxygen is non-polar and unreactive toward water, so it dissolves least. This is option (D).
\[ \boxed{\text{(D) }\text{O}_2} \]