Yes gym work on knees is a great way to deal with knee pain for runs, and is the solution. How its usually caused is by a sudden increase in mileage without building it up, for example not running for 2 months and then suddenly doing a 20-50km week of running, your knee are not used to that load because of the long break and you haven’t given it time to get used to it so that one of the more common reasons knee pain happens. How to prevent it is by slowly build up milage consistently, i would always recommend runners to start doing 1km everyday for 2 weeks then build it up to 2km per day for maybe another week and now when your legs feel comfortable running it should be ok to then add in a couple 5ks and maybe even a 10km in a week with some rest. That way your knee get used to the running load. So theres a way to prevent it and a solution