Depends how long?
If your teeth hurt on both sides this could be tmj.
Any difficulty with chewing? If one sided likely molars moving. Bruxism or clenching your teeth at night might be possible.
If the problem has been only a few days probably no immediate need to see a dentist, but if for weeks then probably a good idea.