I want to add to the answer by Rob, the eye of the experimenter.
You ask:
Why does quantum theory predict that there are an infinite number of quark-antiquark pairs in a proton?
Quantum theory developed because classical theories could not fit the data from experiments examining the details of matter at small dimensions. The experiments with scattering electrons and light on atoms showed that atoms had electrons and positive hard cores of even smaller dimensions.
The atoms were seen to have a cloud of electrons around a positive center with very much smaller dimensions than atomic distances, the nucleus. Further experiments with higher energy projectiles of deep inelastic scattering on nuclei helped to discover the periodic table of elements, composed of protons and neutrons. The data from higher energy deep inelastic scattering on protons allowed to see that there was hard scattering that resulted in the creation of jets of particles coming out of individual interactions,
here is an event

Real proton-proton collision event at 13 TeV in the CMS detector in which two high-energy electrons (green lines), two high-energy muons (red lines), and two-high energy jets (dark yellow cones) are observed. The event shows characteristics expected from Higgs boson production via vector boson fusion with subsequent decay of the Higgs boson in four leptons, and is also consistent with background standard model physics processes.
Meticulous studies trying to find a model for the data came up with the quark model and finally the SU(3)xSU(2)xU(1) current standard model. The quarks cannot be seen but the field theoretical model is very successful in fitting a large plethora of data.
This is what you describe as an infinite number of quarks and gluons,

Snappshot of a proton -- and imagine all of the quarks (up,down,and strange -- u,d,s), antiquarks (u,d,s with a bar on top), and gluons (g) zipping around near the speed of light, banging into each other, and appearing and disappearing. (M.Strassler 2010)
BUT you are not aware that in field theories the particles shown in the proton are virtual. . Virtual means that in the mathematics of the theory the mass of each depicted as quark anti quark gluon is off mass shell, it does not exist outside the nucleus. Only the accumulation of scattering events on the protons , in the first image, can be predicted by the field theory mathematics, and the fits have given rise to the parton model of the nucleus.
See some parton distribution functions

If you go to the link you will be able to enlarge and see the individual plots for quarks etc.
So the infinity is a mathematical infinity, and for each individual scatter what is important are the conservation laws as Rob describes.