I agree completely with what canadianbacon says, but will toss out a couple of other thoughts.
Onions, like garlic, are members of the allium family. When they are cut, natural components of the onions or garlic are converted by enzymatic action into allicin, which breaks down into sufphide components, which gives the onions or garlic their strong, stinky smell. The chemicals in uncooked onions or garlic intensify with time (and more so the finer the dice) and, if the onions or garlic are left uncooked, any sauce you put them in is likely to become stronger with time and not particularly useful. Cooking seems to neutralize these chemicals and result in a more stable sauce (and a more flavorful one) when the cooked onions or garlic are incorporated into the sauce. If the sauce is to be used shortly after making, you may be able to get away with using raw onion (or garlic). But if your sauce will be sitting around a lot, or overnight, I think you may want to cook the onions.
Another possible reason for cooking the onions (or garlic)--a less Alton Brown-ish explanation--is strictly cultural. Italian cooks traditionally do not use raw onions or garlic (except for some sweet onions in salads, etc.) in their cuisine. And tomato sauce is about as Italian as it gets. So it's possible that the cooking of onions and garlic is just part of that cultural tradition that has been passed down from generation to generation through the ages.