You have to be careful when stretching a muscle.
Do not stretch a muscle when your body is cold. The muscle will not be elastic and stretching a stiff muscle can cause pain. Try to do a light warmup and or at the end of your training before you stretch. This will allow the muscle to be more flexible and less susceptible to pain. Also do slow sustained stretches and not quick sudden stretches.