How does this work?

2 gyms in the same level 17 s2 cell, neither are sponsored. Why are they both in Pokémon GO?

There can be a lot of answers to this. The most common one is past abuse when location edits could be done over much larger distances than they can now. More recently there have been delays in the algorithm being recalculated after a location edit involving a gym, but one will usually go away with that glitch.