the age where you gain the most weight is the year you figure out how to dial in your diet and train. if i knew that information at 17, then 17 would be the magic year. 17-25 is probably the easiest years to gain mass, though again - without the knowledge or dedication, results will vary radically.
with regards to me personally, i have been vaguely going to the gym since 15. when i say vaguely, it was hopping on the incline/flat bench, and 2-3 other exercises 1x per week. occasionally lifted while in service, though never more than once a week. stopped lifting at 22, and started again at 29 - this time i took it serious, and that is when i had gains. plateau'd at 152 pounds and 3.8k calories daily, and had to join AM to figure out how to keep growing.