Swayback-technically called "lordosis"-is the deeply sagging top line that develops in some older horses. Swayback, lordosis, is caused by weakness and laxity/stretching of the supporting ligaments along the horse's spine, often with weakness and loss of bulk/tone in the top line musculature.
To a large extent, lordosis is an aging change caused by the forces of gravity on the spine over the years. The weight of the horse's chest and abdominal contents constantly pulls the back down. It's common in aged broodmares, who have had the added weight of a pregnancy stressing the back. Letting the horse get too fat obviously contributes to strain on the back. Similarly, carrying a heavy rider for many years might increase risk, but this has not been specifically studied.
Conformation also plays a role. Horses with overly long backs are more prone to back problems in general, including swayback. Horses with high-set necks and a high head carriage may be at higher risk because this way of moving tends to hollow the back.
Finally, age-related weakness in ligamentous tissues, together with loss of muscular tone and bulk related to aging, lack of exercise and some diseases (e.g. Cushing's disease) can eventually lead to a poor ability to fight gravity.
There's really no way to accurately predict which horses will become swaybacked, but the more risk factors, including multiple pregnancies, age, long back, the greater the likelihood. Complete prevention may not be possible, but horses that remain active into their older years and are kept at a normal weight (not fat) are less likely to develop lordosis.
If you can't always ride your older horse, at least consider trying to keep to a schedule of light regular groundwork, including exercises for the back. If you see lordosis developing at the same time as a big belly, and loss of muscle size and tone elsewhere on the body, ask your veterinarian if testing for Cushing's disease might be in order. The muscular changes of Cushing's are easier to control and reverse in the earlier stages of the disease.