I have a similar problem that comes and goes - turns out my jaw dislocates when I open it wide. Sounds horrible, but it's pretty common. It started in my teens - hurts to open it wide and sometimes it gets 'stuck', which is really painful. My dentist refered me to the hospital - which confirmed with x-rays that my jaw pops out of place.
It can also be due to grinding your teeth or clenching your jaws (usually when tense). This aggravates it for me.
I now have a type of specially made gum shield that I wear at night to stop me grinding my teeth and to keep my jaw relaxed (the pain is caused by the muscles spasming). I also take anti-inflammatories when it is bad and cut food (such as apples) into pieces rather than trying to get my jaw wide open.
Best bet is to go to your GP and see what they think.
It's not a dangerous problem or anything to worry about. Since I've followed the doctors' advice I've been free from pain and 'locking' for years.
Hope you feel better soon.