How does exercise burn fat and build muscle?

Repetitive use. Repetition is how we replace fat with muscle. Take running. The act of lifting your leg (which is heavy), rotating your pelvis to swing your leg to place it in front of you, and repeating with the opposite leg is a lot of work. Do this 5000 times. Eventually, fat, which doesn't help with action, is replaced by muscle. Exercise also requires calories - the body breaks down fat for fuel.