I sometimes ride with "beginners" who are just getting into the sport. Part of an informal obligation I feel when going on these rides is to offer encouragement and a sense of belonging. I chat them up and compliment them on their bike or whatever to gain their confidence. Then I'll ask general questions about how they like the bike, how did they fit themselves to the bike, etc. This may let them feel open to suggestions. Sometimes I will ask for their advice about shifting or whatever. A common response might be, "I don't really know." Then I might say something like, "I've heard that..." Or "I read that...."
But if I see someone I don't know who looks like he could use some advice, I never say anything to that person. I do what all other bikers do, wait until he is out of hearing range then say something snarky about it to my riding partner. (just kidding)