People get sore muscles for three reasons:
- They are not used to exercising.
- They are used to a different exercise.
- They push their regular exercise too hard.
You said that you recently went from 30 minutes to 40 minutes. Your pain is most likely from your body adapting to the new mileage.
Although you should make sure you are doing your part by:
- Ensuring that you have proper running shoes.
- Giving yourself enough rest.
- Giving yourself enough water and food/nutrition.
Also be aware of the surface you are running on. Always on the road or bike trail? Treadmill or grass? You may try running on a different surface to mix-up your workout and give your body an easier/harder workout depending on how you feel.
I would give yourself a day of full rest and see how your legs respond. Feel good? Go back to running 30 minutes for a day. If you're feeling good, next run do 35 minutes. See how we're working our way back up to 40 gradually? Perhaps you increased the time/mileage too much and need to taper down.
If the soreness does not go away after 2 days of rest, I would definitely consider seeing a medical professional just to make sure no damage has been incurred.
You may also want to follow a training program like Hal Higdon's 5K so you can vary your workouts/runs.