Why do people go to the gym to socialize?
There are three reasons that I can think of:
First, if you're into physical fitness, the gym is a great place to meet like-minded people. I've been interested in strenuous exercise since I was 8 years old. It's difficult to find people who are willing and able to talk about fitness if all you encounter are people in the workplace, or at school, or in limited social situations. Most people cannot identify with strenuous exercise, and their only relationship to exercise is as a vehicle to weight loss. But there's much more to fitness than weight loss, and it's fun to talk about all those things with people who share the same interest in it as I do. Where can you find many such people? The gym.
Second, this is hard to explain to people who dislike exercise, but the gym is a really fun place for people like me. I could spend a whole afternoon in the gym if I had the time. I'd lift weights, do some cardio, swim in the pool, relax my muscles in the jacuzzi, spend some time in the sauna, take a nice hot shower, etc. I imagine many people feel the same way about spas that I feel about the gym. It's just a nice, relaxing place where I can do all the things I enjoy and pamper myself a bit. Given how much fun it is to go to the gym, it's not surprising that when friends go to the gym together, it becomes a social experience.
Finally, if you go to the same gym often enough, you'll end up face-to-face with the same set of strangers every day for months or years. If you take showers at the gym, you might even find yourself naked in front of these strangers every day for months or years. It's simply awkward and strange to have a shared experience with someone every single day for an extended period of time and not end up chatting and befriending these people. It's inevitable, really. You'd have to be pretty anti-social to ignore someone you see naked or half-naked every day, wouldn't you? Socializing with these strangers - who soon become acquaintances - is inevitable.