You can not avoid weight gain in old age
Reduced physical activity and lower metabolic rate caused by a loss of lean body mass (muscle) may be the reason for weight gain but it is not that you can’t avoid this situation. The lifelong loss of lean body mass reduces our basal metabolic rate as we age, it's a very small change that begins between ages 20 and 30. The percentage of body fat gradually increases, and it produces an ever-decreasing calorie requirement. That's because fat cells burn fewer calories than muscle cells. And a lower metabolic rate means that unless you eat less, you'll gain weight over the decades.
But exercise can mount a two-pronged attack on middle-age spread and muscle loss. Any activity makes you burn more calories (so you're less likely to wind up with an excess). And strength-training can offset the loss of muscle mass.