The Rabbis forbade taking medicine on Shabbos (barring the person being sick), because they were worried one might come to grind medicine on Shabbos (think mortar and pestle), and grinding on Shabbos is a Biblical Prohibition (Tochen).
In the time of the Gemara (and perhaps now, although I'm not aware of it) people would take medicine, in order to sweat for health reasons. The Rabbi's therefore forbade any activity that would cause one to sweat (i.e. exercise) because they were worried that if they permitted exercise, it would lead to people grinding medicine in order to sweat.
See here for more details, and especially take note of footnote 3:
If the purpose of the exercise is to work up an appetite, it is questionable; see Sha'ar ha-Tziyun 301:9. If the purpose of the exercise is to lose weight for health reasons, it may be prohibited, since weight loss can be (partly) accomplished by taking pills. If the exercise is for pure enjoyment, it may be permitted according to the basic halachah, although it may be considered uvda d'chol, "a weekday activity." A rabbi should be consulted.