The hamstring is a muscle that runs down the back of the thigh. Ham is meat from the upper part of a pig's leg. The word "ham" can be found in "hamstring" and the joke is referring to a pig that quit running a marathon due to a hamstring injury.
Why did the pig quit running the marathon ? He had a problem with his hamstring .