I get them all the time, trick for me is recognising it before I start trying to force it and crash!
As for fitness, for me it’s compounding/exponential. So the first week hurts, the second week feels better, the third week feels better again, by the 4th I wonder how I ever coped in week 1, a couple of months in after a break to ride the road bike for a bit for a change getting back on the mtb feels like it’s got an electric motor.
I missed most of the winter and upto May with work. Made a concerted effort since then and I’m back doing ‘brisk’ club runs at 17-18mph and still feeling stronger every week (brisk went from painfully, to manageable to something I could do with a 50mile solo ride earlier in the day already in my legs).
Keep at it. It will take less time than you think to get fit and find the fun in it again because each week/month feels so much better than the last one. You just have to get through that initial shit bit from zero to something. Riding with groups helps a lot.