The Twelve Apostles elected by Jesus were not meant to live forever and rule the earth. They represented the fathers of Christianity and the church.
Judas was a betrayer. He betrayed his master Jesus, which is the same as betraying the whole group of twelve, and it implies that he is no longer a part of the group of the Twelve Apostles. Judas deserted the company of Twelve. It was now necessary to replace the office of Judas, possibly because they believed that 12 was the divinely appointed number by Jesus Christ and it should be maintained. The number twelve might also represent the twelve tribes of Israel. Thus, it seems like it was necessary to continue the tradition of the number Twelve.
The death of James did not end his position in the Twelve as he was not a betrayer like Judas. In fact, all the apostles (according to tradition) were martyred. They are now all dead and probably are now in Heaven, occupying the Twelve Thrones reserved for them in Heaven (my speculation).
And, Jesus did not elect Twelve Popes, rather Twelve Apostles.