It is hard to say without more info.
But you may have injured the ligaments that stabilize your knee cap. If that is the case, flexion of the knee can cause the knee cap to begin to sublux or even dislocate from the knee. Often therapy to strengthen a muscle known as the vmo helps. If not, surgery may be required. Thank you fir the question.