It’s very rare to see a person with a tight muscle, ask them to stretch it and then have their pain stay away. Usually there’s a reason that the muscle got tight and that’s what needs to be addressed.
There are certain instances where it’s just a sudden overload from doing too much too soon, like a long hike which was a once off. In those cases, once you address the restrictions very soon after, you probably won’t have an issue once everything loosens up again.
But for any sprain, strain or chronic pain you better have a more rounded plan than to stretch! You need to think about loading and correcting movement patterns because it’s the way you’re moving (or not!) that is causing the issue.
The brain needs a reason to change, which is where loading a new movement comes in. If the brain sees a new way of doing things as being more efficient, you’re onto a winner. Once you repeat the process over a long enough time (depending on how long you had the issue for, this could be days, weeks or months) then you can achieve a positive change that sticks.
This is why leading an active life full of variety is hugely beneficial and why your gym plans should change periodically both in terms of volume, intensity and exercise selection.