I also have had this problem, it took me about 3 years of trying to fix it but now it is finally gone/manageable. I want to share the things I did to fix it, I really hope my experience can help someone else.
It started when I had a period of being extremely stressed and it turned into depression. I had extremely sore mouth especially down either side of my tongue, it felt red raw and like I had been chewing on the sides of my tongue (but I wasn't). I was in constant pain all day every day it was unbearable. I went to the doctor and he said "I'm not sure what it is, drink more water, if it keeps happening come back." he also suggested I use coconut oil and swish it around in my mouth for 15-20min and then spit it out. This is what I would later find out to be "oil pulling"- which i would recommend (google it for more instruction).
I put up with it for a while longer scouring the internet for help, the only thing I could find were people saying they had surgery to remove the sides of their tongue!? ouch. I felt really helpless.
Then went to a Naturopath, he said it was from stress and basically said I need to just reduce/ manage my stress, so that's what I did. I started dealing with the underlining problems that were causing my depression, it was really hard but once I started facing them head on it got better (very slowly). I had stopped exercising during this time and I knew that when I didn't exercise or get out of the house/ be active with my friends the pain got a lot worse (my stress reduced when I was exercising and being social, it was also a good distraction from the pain) I joined a weekly beginners Yoga class (so good for stress management! plus its social and a good work out) and after a while I also joined a women fitness class (just a cheap class in the park using some weights and body strength and a little cardio, this was also super social)
So far all of these things helped, but it never really went away. I was still in a lot of pain on a daily basis. This is when I started noticing the difference in pain when I was eating different foods, when I was eating badly like processed sugar or processed foods the pain was unbearable and when I would heat healthy whole foods (fruit, veggies, protein, home cooked meals) the pain would reduce! so I started cutting the processed foods out of my diet. It was really hard and it took a long time to get it right but after doing it for a while I saw a big improvement in the pain, I eventually decided to give up processed gluten too which had helped again!. At this point I still felt the pain, but it had drastically reduced and as long as I was eating well the pain was completely manageable and I was pretty happy living like this for quite some time.
The most recent thing that has happened is- My sister made me go to her Naturopath who id never been to before, she did her initial consult and said the one thing she thought I could work on was my stress ( I thought I had) she explained that compared to where I was 3 years ago my stress levels were great, but my body was showing that I need to do some more work on it. I asked her about the pain in my mouth at the end and she said its definitely the stress and that my body needs some help. She recommended oil pulling, and some natural supplements to support my adrenals and stress management and stress response (Adreno Tone & CalmX), I also take Evening Primrose Oil to help reduce PMS which helps to reduce my stress lol and a good probiotic to keep my gut healthy which helps keep the balance too!
She also recommended I keep a health diary, I just write down a few notes every day about my stress levels during the day, what I ate, and anything else I want to keep an eye on (pain, headaches, etc) and this diary has already helped me to pinpoint some things I can work on and change in my life to reduce the stress!
I don't recommend trying to treat it on your own, I recommend looking around for some great Health professionals for support, a great GP & Naturopath to help you out. If you are not getting any help from a professional keep looking around until you find one who will help and support you.
I know every ones journey is different but these are the things that helped me, I hope it can help at least one person!
All the best