May be due to disloaction of patella...or tearing of ligaments. And mensicus or due to wekening of vastus mediallias which cover the patellla mostly and provide fixation to it on the medial side
A cramp bandaid would work initially, and if the pain continues x-ray imaging and orthologist consultation is suggested
It may also be a congenital issue. You may need to do a lateral ligament release.