Quarks are described by the standard model of physics, which is a field theory: it describes particles in terms of more fundamental fields and symmetries. It is in a sense these fields that actually exist, and each individual quark is just an excitation of the relevant quark field. How these fields interact is described by the standard model Lagrangian, which is largely set by a set of symmetries between different particles and forces.
I interpret your question as what conditions there are for the appearance of quarks in the model. Most primarily there has to be a world the model applies to: without spacetime or a world implementing the "rules" of quantum field theory for example the model is not applicable. One could also imagine that there could be particle fields with no excitations ever showing up; such fields would need to be unconnected in the Lagrangian to all the other fields (right now only some particle fields are unconnected to some of the other fields, e.g. how neutral particles don't "feel" the electromagnetic force and leptons do not "feel" the strong force). But quark fields are connected to more or less everything.
There are likely some more complex conditions described in quantum chromodynamics that determine when quarks can show up too.
But I think the question basically boils down to "why the standard model, and its symmetries?" A very good question I don't think we have any satisfying philosophical answer to (the physical answer is of course "because it fits the observations well").