It's probably certain muscles being worked more than others and in a result the knee cap gets pulled out of place, and isn't aligned correctly. This was what my doctor told me and rehab also, if this is what you have, it's not a big deal, exercises that I did were seated no weight leg extensions, and squeezing when I locked out to try and strengthen all muscles connected to the knee cap.
If it is really that bad you should go to a doctor and if the recommend it, go to physical therapy.