This year we saw the first ever amateur to qualify for the world championship. By what route was he able to even take part in qualification? If only 128 players are ranked, what decides who can take part in qualification events?
According to the Wikipedia article about him, James Cahill received a wildcard from the organization:
At the 2019 World Championship, Cahill gained a place in qualifying having been given a wildcard place by the World Professional Billiards and Snooker Association, despite being an amateur.
As for the rest of the participants:
The top 16 players in the latest world rankings automatically qualified for the main draw as seeded players.
so they weren't among the 128 participants (which you refer to) for the qualifying draw.
The qualifying draw consisted of 128 players, including 106 of the remaining 112 players on the World Snooker Tour, as well as twenty-two wildcard places allotted to non-tour players. These invited players included the women's world champion, the European junior champion, and all four semi-finalists at the amateur championship.