The most common disease to cause a fish to swim sideways is swim bladder disease. This "disease" is a actually a broad term for a variety of symptoms such as swimming sideways, upside down and leaning to one side.
This is a non-contagious disease but also indicates that other fish in the tank may develop symptoms. It is typically a reaction to the goldfish's diet. Of the many causes, some of the more common stem from taking in too much air while eating, and from eating too much or the wrong type of food. If digestion is not regular, this affects the swim bladder, which controls swimming stability. This easily cured disease can usually be treated by a few home remedies which include checking the water quality and temperature, 48 hours of not feeding, and feeding small amounts of shelled peas.
Diets that include blood worms, brine shrimp, shelled peas and boiled vegetables help maintain digestion. Soaking pellets in a separate bowl of water prior to feeding ensures that they sink. This helps decrease fish from swallowing too much air when feeding. Adding aquarium salt helps decrease the stress of the fish. If necessary, there are swim bladder treatments available over the counter. These can be used if the disease is caused by an infection of the swim bladder.