Color confinement is still an unsolved problem. But our best guess so far is that it's a side effect of gluon self-interaction in the strong-interaction limit. Here's a hand-waving, non-rigorous argument as to why it happens.
When one separates two (anti)quarks/gluons past about 10^(-15) m, the potential energy becomes approximately linearly proportional to the distance, almost like stretching a string. In fact, string theory was first developed to account for the properties of hadron excited states. But if this gluon string gets long enough, it can pull quark-antiquark pairs out of the vacuum and snap.
This accounts for jets of hadrons produced by high-energy collisions. A speeding quark or gluon stretches a gluon string behind it, which repeatedly snaps and makes hadrons.