How can I avoid this in the future?

Wow. Some guys are such losers.
How sad to make someone feel self conscious about working on self improvement.
I'm proud of you for pushing yourself. Keep it up. All it takes is focus and perseverance.
I went through something similar when I was 34. I had gained weight over 5 or 6 years due to a job and change in lifestyle. I went on Weight Watchers and started working out and walking at least a mile or two a day.
I got back in shape and looked really good again. I started dating again and had a couple of amazing girlfriends. Then I met my future wife when I was 40.
tell the owner of the gym they will do something as they want your money too
Go to women only sessions if possible. Being with men in a gym is often very awkward and toxic.
Opinion
2Opinion
Go to planet, fitness they thrive on a no judgment zone and even have it written all over the walls
Keep going to the gym, eventually they will start looking for another reason, remember the ones that were nice and the ones that made fun. Do not give up, you got this
Superb Opinion