Hi 小二的歌,
'Stroking your ego' is an idiomatic expression that means roughly 'to make one feel good/superior about oneself'. This is often used in a negative way if talking about yourself. The example you mention uses it to refer to people who go to the gym to show off (i.e. they are already good at it & do it to feel superior to others instead of to improve themselves).
It can also be used for others: e.g. 'She stroked his ego by asking him a lot of questions about motorcycle maintenance.' In this example, the man is good at or really enjoys motorcycle maintenance. The woman is showing an interest in this in order to flatter the man or make him feel good.
Hope this helps!