Can I wear sunscreen to the gym for exercise?

Yes, you can.

If you only wear a sports vest, it is likely to cause skin damage due to some friction with the ground. So when you go to the gym, you can apply a layer of sunscreen outside, which can protect your skin well and avoid direct sunlight.