Cities do buy apartment complexes and sometimes houses but they veer towards larger buildings. But the only reason they usually start doing that is if they need to redevelop the area or provide more affordable housing without building from scratch. However, I know in the Bay Area it is a very complex and drawn out process to apply for the city to consider the property to purchase since they do not purchase many at all.
Every city though has different guidelines on how they approach affordable housing and redevelopment areas so it would be best if you checked with your housing department for your city or county to get more detailed information. I see your zip code is in Pittsburgh, so I provided a link below to go to the housing department's website for your area.