There are jokes which go around about priests who were “born a monsignor and wanted to be bishop by the time he reached major seminary”. I can’t say that a certain amount of brown nosing and politics doesn’t play a part sometimes.
But, in the larger scheme of things, what really happens nowadays is that the pope calls certain priests to serve as bishop.
Let us remember that in the Church, the ministry of the episcopate is not so much one of “moving up the ladder” as placing oneself at the feet of the faithful in humble service. Or at least that is what it is supposed to be if the position isn’t abused.
Any priest (or really any male Catholic for that matter) could become a bishop, whether he is diocesan, religious, or whatever. There are good arguements for “promoting from within” but that doesn’t necessarily happen a whole lot these days where the bishop comes directly from his own native diocese.
Every so often, there is a kind of canvas sent around to bishops (and possible a few notable lay faithful also) asking for the names of men who might be thought of as good candidates for bishop. These are sent on to the papal nuncio (representative to a country) who forwards them to the Congregation for Bishops. The Congregation kind of vetts through these names and considers other factors about a diocese where the see is vacant (or soon to be) and makes recommendations to the pope. The pope makes his appointment, the nuncio calls the priest and asks if he accepts. Assuming he does, the announcement is made that this man will be the new bishop of that diocese and in time he takes possession of the cathedral and royal, teaching chair. The pope issues an official document (called a bull) instituting him as bishop.
As for cardinals, it is entirely up to the pope. A cardinal is a member of the papal court of advisors and is made a member of the Roman clergy (following the traditional practice whereby it was the Roman clergy who elected the Bishop of Rome). Typically, cardinals are either notable men (usually bishops, but not always) and/or bishops who hold signifigant positions in the life of the Church and the world. From this we get the term “cardinaliate see”, as there are certain dioceses which by their nature generallly seem to have their bishop made a cardinal. For example, Chicago is considered such a see. It is pretty much expected that whoever is made Archbishop of Chicago will soon get his red hat because is the position he holds. The fact that whoever is the bishop of this place will most likely be made a cardinal also probably holds some sway when the determination is made as to who will be appointed to this see in the first place.