The YMCA, or Young Men's Christian Association, was intended to provide cheap temporary accommodations and resources in urban areas with a wholesome Christian environment. There is also a system of YWCAs, or Young Women's Christian Association. The sexes were segregated to aid in keeping the environments "wholesome."
At one point they were both considered a nice and reasonable place for travelers, or young people new to a city, to stay. As the organizations grew, they began to provide more resources like gyms, pools, lectures and learning opportunities at cheap to no cost in an attempt to aid the urban working class and poor. The housing provided by YMCAs are now typically more for people in serious financial trouble or people who are homeless.
They really were not hook-up places or bathhouses. After people began to be more aware of homosexuality, the fact that the sexes were being segregated began to start some rumors and jokes.
It is often asserted without proof or documentation that YMCAs were gay cruising spots.There were probably some isolated instances where some men were able to meet there in certain cities, but it would never have been open or flagrant as these were institutions supported by Christian money and had clear mandates. And in no way would it have been common across the country.
At the time of the song, the housing provided by YMCAs were already considered by many acceptable only for people in need, and not really so much a "fun" place to stay. After the song came out the gay rumors and jokes became very common. At the time of the song, bathhouses and hookup spots were common, and trying to secretly meet in a YMCA would have been unnecessary. But after the song, the rumors and jokes about YMCAs became common, even if unsubstantiated.
One way to interpret the song is that YMCA is being substituted for concepts like bathhouses. But it is probably better to just see the song as trying to express the fun of being around other similar men at a time when such things still couldn't be discussed in the mainstream.