I would feel horribly patronized in this scenario. I don't go golfing to get better at it, I go golfing to relax. Similarly someone can program and not necessarily want to be better at it. It depends on their goals and desires. Giving someone advice before asking means you have to guess at what their goal even is. In many contexts (work) this is fine but in general it is not.
To answer your question, the reason why someone might reasonably take offense to unsolicited advice is that unsolicited advice is inherently condescending because it implies that the advisor knows more about the topic than the advisee. It also implies that the advisor knows the advisees skill level and goals. It's kinda insulting, and in another way it's almost controlling as the advisor reframes the discussion around "being good at X". I don't want to be good at golf, I want to enjoy my time golfing.