It’s less complicated than one might think, actually. The Papal Nuncio (the Pope’s representative in a country) solicits names that members of the Bishop’s conference in the area put forward and then selects three of those names to be forwarded to the Pope (the Holy See). The Pope then meets with the Nuncio most often and asks some questions and they decide what person might be best for the position. The bishop functions in a diocese (a local geographic area) as a CEO would in a corporation. They are in charge of the local governance of the diocese. Therefore, the local area does have some influence over who gets to be bishop of the diocese, however, the Pope is free to choose none of the candidates and choose another person of his choice. This rarely happens though.
In essence, often the Nuncio hears good things about a candidate who is a pastor of a church and therefore he makes a note to do further research on this person’s qualities. Obviously, people who work in the diocesan administration already may indeed be more obvious choices for Bishop since they are more well-known to the Nuncio.