Idk how
Niantic does not talk about gym or pokestop creation
The community has observed that it is based on some mapping software, and follows a pattern.
It is a bit technical but this article explains the basics.
https://pokemongohub.net/post/article/comprehensive-guide-s2-cells-pokemon-go/
If you want to know about your local area please give the GPS co ordinates so we can find it and comment
Gyms are upgraded pokestops. The upgrade is applied, we believe, based on the density of pokestops in the area.