Canon 377 states it clearly: "The Supreme Pontiff freely appoints bishops or confirms those lawfully elected."
Over the centuries there were different methods of election. Almost everyone, for instance, has heard how St. Ambrose was made bishop of Milan by acclamation of the people. And in some instances treaties between the Vatican and different countries gave their governments the right of nomination or presentation of candidates for bishop.
The Second Vatican Council determined that such rights should not be granted in the future. It also asked that, where rights of nomination or presentation had been granted in the past, the civil authorities would waive them.