Knee pain that occurs around the kneecap is usually called Patellofemoral pain and can be caused by tightness in the Rectus Femoris muscle or an imbalance between the Quadricep muscles that stabilise the patella. One way that this occurs is through weakness of the Gluteus Medius in the hip. The Tensor Fascia Latae muscle is an internal rotator of the hip so if it compensates for a weak Gluteus Medius, The knee sways inwards towards the centre-line of the body, and any exercise performed with the knee in incorrect alignment reinforces bad alignment and creates imbalance in the Quadriceps, which leads to misalignment of the kneecap and pain.
Also, if you have an anterior pelvic tilt, the hip flexor muscles tend to be overactive as pelvic stabilisers, which contributes to weakness of the Gluteus Medius.
Those with kneecap pain can check if this is the problem in the following way: in Utthita Hasta Padangustasana without holding the toe, bend the knee to squat, only as low as is comfortable. If you can’t hold the knee stable and it wobbles from side to side then hip stability is lacking and you need to consult a Biokineticist to retrain the hip muscles, as well as to re-balance the Quadriceps.
Sometimes knee pain of this nature is also just from tight Quadriceps, mostly the Rectus Femoris muscle: people love to stretch their Hamstrings in yoga, but neglect to stretch the Quads, or they stretch their Quads with the hip in a flexed position- The hip must be extended if you want to stretch the Rectus Femoris.
Pain around the kneecap has a variety of other causes besides the ones mentioned and if pain is persistent, it needs medical assessment.
Ellenbecker, De Carlo, DeRosa, 2009, Effective Functional Progressions in Sport Rehabilitation
Cash, 1996, Sport and Remedial Massage Therapy
Sports Injury Bulletin: Gluteus Medius
Sports Injury Bulletin: Knee Rehabilitation