Why is exercise good?
As jamesqf points out in comment, "the less we use it the longer it lasts" isn't always true even of machines. Sometimes if a machine isn't used, the moving parts start sticking together through rust or other decay processes, which does not happen when the machine is used and the moving parts move regularly against each other.

Another example that comes immediately to mind is a hybrid car, which needs to be driven regularly or the battery runs out. Granted this doesn't affect the car's longevity (I think?), but it is another example where use maintains functionality better than disuse does.

This is even more true when we actively maintain machines, fixing them as they break, replacing parts, oiling, etc.

The key point here is that decay is inevitable. It is a law of thermodynamics, and it doesn't care whether something is in use or not. Granted, things will sometimes decay faster if they're used, but not always, and they'll always decay either way. The only way to forestall decay is active maintenance. This isn't contradictory with decay being inevitable, because you can actively maintain something only for so long (it takes work and energy).

This is relevant to biological system because that is how our body works: it is constantly self-repairing and self-maintaining, for the length of the person's life. One reason we die is that it stops doing so as efficiently as one ages. But as long as we are living, these processes mean our bodies aren't a static object: they are a dynamic system that is constantly reacting to outside and inside stimuli. And that system, including the self-repair mechanisms, are set up such that they work best within a certain range of motion and activities. It so happens that range doesn't include "no motion or activities". Likely because we evolved as an active species, so being able to function efficiently when active is useful, and some of the things that make us able to function efficiently when active can cause some harm when we aren't. For example, we store fat in order to use it when food isn't available and as fuel for effort, but if too much of it accumulates it has effects on hormones and inflammation that our bodies don't deal with well. Another example is how our muscles waste away when we don't use them; this is useful for an active species that needs the muscles it uses and shouldn't waste energy and protein on those it doesn't, but an inactive species might be better off conserving its muscles through periods of inactivity, so that they would still be capable of moving well those rare times they do need or want to.

Having said that, look at high-level athletes getting injured, getting early arthritis, etc... It is possible to exercise more than the body's self-reparation abilities can handle, and that also leads to health problems down the road.