Leaving the specified amount of headspace in a jar is important to assure a vacuum seal. If too little headspace is allowed, the food may expand and bubble out when air is forced out from under the lid during processing. The bubbling food may leave a deposit on the rim of the jar or the seal of the lid and prevent the jar from sealing properly. If too much headspace is allowed, the food at the top is likely to discolor. Also, the jar may not seal properly because there will not be enough processing time to drive all the air out of the jar.
The amount of headspace depends on how much the food moves or swells inside the jar during the canning process. In the case of spaghetti sauce, there is a lot of food material and more viscosity or thickness compared to a tomato juice. So the food pulp/pieces are going to shift or swell more than a juice, therefore they need more room. Also, how the heat moves through the jar, by convection or conduction, can influence the amount of headspace needed.
Reliable recipes will specify the amount of headspace needed for that product. In general, jams and jellies are 1/4 inch; pickles, fruits, some tomato products are 1/2 inch; and plain vegetables and meats are at least one inch.
Source: https://nchfp.uga.edu/how/general/ensuring_HQ_canned_foods.html