Several things could be causing this and you'll have to go to your doctor to find out.
One of them is called "Baker's cyst' which refers to accumulations of fluid that often causes swelling and pain behind the knee and an inability to stretch your leg out fully. Sometimes the swelling is not particularly evident and you may need to compare one knee to the other. If there does appear to be some swelling there you could try ice packs, keeping your leg elevated and anti-inflammatories (NSAIDS) to reduce the inflammation.
Bursitis - or the inflammation of one of the bursa sacs that reduce friction in your knee can also cause pain and an inability to stretch out your leg.
There are other possibilities but you'll have to get to a doctor to find out what's going on. Good luck!
We hope you find this general health information helpful. Please note however, that this Q&A is meant to support not replace the professional medical advice you receive from your doctor. No information in the Answers above is intended to diagnose or treat any condition. The views expressed in the Answers above belong to the individuals who posted them and do not necessarily reflect the views of Remedy Health Media. Remedy Health Media does not review or edit content posted by our community members, but reserves the right to remove any material it deems inappropriate.