They have fractional charges because that is how we happen to measure charge. If our unit of charge had been set when we knew about quarks, we would have chosen those as fundamental, and the charge of the electron would instead be -3.
Now, the ratios between these charges appear to be fundamental. But the presence of fractions is arbitrary.
Isn’t charge quantized? Observable isolated charges are quantized in units of e. You can call it -3 and +3 but that just changes the relative value for the quanta. The interesting question is still why the positive and neutral particles are nonelementary particles made up of quarks with a fraction of e, the math made possible only by including negatively charged ones (and yet electrons are elementary particles).
> If our unit of charge had been set when we knew about quarks, we would have chosen those as fundamental, and the charge of the electron would instead be -3.
Actually, I doubt it. Because of their color charge, quarks can never be found in an unbound state but instead in various kinds of hadrons. The ways that quarks combine cause all hadrons to end up with an integer charge, with the ⅔ and -⅓ charges on various quarks merely being ways to make them come out to resulting integer charges.