Without knowing your training regimen, it would be difficult to say exactly what is the problem. We can tell you some of the more common mistakes cyclists make. Perhaps changes in one (or more) of these areas would be helpful to you.
First of all, advancing your training program too fast and too intensely could be the biggest factor. An athletic trainer or fellow cyclist may be able to help you identify how you can progressively build up frequency, intensity, and duration of your training schedule.
Secondly, have someone review your equipment. Using the right kind of shoes is important. Having your bike seat set at the correct height and angle can be a key risk factor for leg injuries.
Overuse and repetitive motion are often the straw that broke the camel’s back, so to speak. Underlying anatomical malalignments of the leg may be what bring on the problems as the training program increases over time. An orthopedic surgeon or physical therapist can examine you and provide direction in this area.
Most overuse or repetitive injuries are preventable. By paying attention to the areas discussed, you should be able to avoid these problems while still advancing your training schedule. Good luck!