There are also other factors. Primarily, IMO, it's the simplicity of playing the game. Basketball, like soccer, requires almost no resources. A ball, 10 guys and a couple goals are all you need. Anyone can participate.
Compare that to, say, lacrosse. Now there is a game only the better to do can afford. Hockey, in most US states, same thing. You need expensive equipment, facilities, travel, the whole nine yards. But, basketball, hell any playground will do.
So, 10-year old kids get weeded out on the school yard. The better ones make the school team. Of those, a few go on to play in high school, aspiring to reach college ball. In the end, a dozen or so every year reach and stick in the NBA.
Lacrosse guy? He's going to college to be an engineer, financier, lawyer or doctor.