Goldfish tend to attack each other when a food source is scarce. Increased competition for dwindling food sources leads to a fight for the food.
Goldfish are omnivorous, so a balanced diet of meat and greenery should be available. A lack of either can lead to goldfish fights over what is present. In extreme cases of hunger, goldfish attack each other in order to consume the meat to make up for what their diet lacks. Being social creatures, pet goldfish identify with their owner and do not eat unless they are fed by a familiar face, so a lack of this element can also lead to starvation, which in turn creates fights.