Let us take a look at what pain is. Basically, pain is a signal to the brain that something is not correct with what is going on in your experience. For example, you touch a hot stove, the pain you feel alerts you to the fact that skin tissue is about to be damaged. As a learned response, we retract our hand from the stove. (How do we know that is a learned response? A drunkard will do all kinds of things that hurts him while he is under the influence of alcohol. The state of drunkardness allows parts of the nervous system to forget what it learned. This is verified in the fact that there is a published blood alcohol level, at which levels we know when driving, motor function, and decision making, is impaired).
In regard to body pains from stretching and exercising, there are different benchmarks as to what is a bad pain (injury, tear) from what is a beneficial pain (being sore from stretching to a new limit, microtearing muscle fibers so they are replaced by longer, stronger, more flexible fibers).
That said, if someone takes off in a quick run down the street, and all of sudden, there is a searing pain in the hamstring, they have pulled (ie torn) the muscle beyond its elastic limits. You should not go home and stretch that muscle. Ice, rest, elevation, massage, are indicated in such a case (but not limited to those treatments). Let's say the pain in this case is an 8 out of 10.
Now, if someone takes a yoga class and comes home with sore hamstrings, you have a different issue. The hamstring is elongated, there are microtears in the connective tissue, and when repaired by the body, the muscle will be much improved in resiliency and flexibility. You can go home and stretch that muscle later that day or the next. Let's say the pain is a 3 out of 10.
But what if the pain is the same in the two cases? Let's say in the first case , the pulled muscle is mild, and the pain is a 5 on a scale of 10.
Let's say in the second case (the yoga class) the exertion was more than usual and the yoga student had a lot of pain in the hamstrings. The pain is also a 5 out of 10.
Well, now you have to differentiate between pains. Knowing how each occured is primary. You should probably rest both, but you can return to stretching quicker from the yoga overexertion because the injury happened at slow speeds. If you try to run fast again, as in the first case, the pull you get will most likely be worse. If you try to stretch the yoga injury it will not hurt near as bad as the pulled hamstring from running fast, even if the pains are both level 5.