Regarding the chemistry of what happened here, @rumtscho's comment addresses that very nicely. Quoting from the relevant portion of the linked answer:
This scum is made from proteins. Meat contains muscle fibers (the proteins actin and myosin) as well as some loose proteins swimming in the fluids within the meat (the cell plasma). When you cook meat, the protein-rich fluids are expelled (that's why overcooking makes meat dry). Under hot temperature, the proteins in the fluid coagulate, making it firm.
As to why that occurred in this case and what you can do about it: you've provided a list of ingredients that includes a lot of moisture, with very little to help bind everything together. Eggs contain a lot of water, and onions will release quite a bit as they cook too. This exacerbates the problem of fluid expulsion noted above. This is why you will very often see breadcrumbs (and sometimes a dry cheese such as parmesan, especially in Italian recipes) included in meatball recipes. They're not just filler; they help to absorb the juices expelled by the meat itself as it's squeezed out by the cooking process. It's a little counter-intuitive, but the dry breadcrumb helps to keep the meatballs moist and shapely as they cook.
Next time consider reducing the amount of egg (you don't specify how much you used, but I rarely use more than 1 egg per pound of ground meat) and adding a bit of breadcrumb to your recipe: perhaps 2 tablespoons per pound of meat as a starting point, up to about 1/4 cup depending on other ingredients. Given the onion and other things here, I would err on the high side of that.