There are two answers to the OP. According to the groups (Orthodox and Protestants) that oppose this doctrine, it arose from usurping what was given to Peter and ignoring Scripture and enlisting secular authority to enforce its view. According to the group (Roman Catholic (RC)) that teaches this doctrine, it originated by “divine institution”. We will look first at what RC says.
CCC-875 … The one sent by the Lord does not speak and act on his own authority, but by virtue of Christ's authority; not as a member of the community, but speaking to it in the name of Christ. No one can bestow grace on himself; it must be given and offered. This fact presupposes ministers of grace, authorized and empowered by Christ. From him, bishops and priests receive the mission and faculty ("the sacred power") to act in persona Christi Capitis; …. The ministry in which Christ's emissaries do and give by God's grace what they cannot do and give by their own powers, is called a "sacrament" by the Church's tradition. Indeed, the ministry of the Church is conferred by a special sacrament.
“Divine institution” thus means God appointed; authorized and empowered by Christ. From the base of CCC-875, which essentially could include any Christian (a minister of grace or of reconciliation (2 Cor. 5:18)), we move to the RC argument that it alone is supreme authority in a nutshell. This latter assertion is obviously very serious for all Christians to consider. If the doctrine is true, then those, be they Protestant or Orthodox, not in communion with the Roman Catholic Church (RC) are against God. If the doctrine is false, then RC is against God.
CCC-881 The Lord made Simon alone, whom he named Peter, the "rock" of his Church. He gave him the keys of his Church and instituted him shepherd of the whole flock. "The office of binding and loosing which was given to Peter was also assigned to the college of apostles united to its head." This pastoral office of Peter and the other apostles belongs to the Church's very foundation and is continued by the bishops under the primacy of the Pope.
The elements supreme, full, immediate, and universal will thus flow from this divine appointment so-called; we will look at each.
SUPREME (Mt. 16:18)
Simon is the “rock” of His Church. The bishops under the primacy of the Pope (Peter’s successor) carry it forward. The keys of the Church (literally kingdom of heaven) were given to Peter alone. Circa 750 CE a bishop sided with Rome’s view on a doctrine simply because when he got to heaven, he wanted Peter to open the gates. Rome had it; the other group did not, went the thinking.
FULL (Mt. 16:19)
While all the apostles were given the power of binding and loosing, it was to Peter first who received said power.
IMMEDIATE (Acts 1:20)
This authority has existed from Christ to Peter onward through a succession of bishops. See also Irenaeus and Eusebius.
UNIVERSAL (Jn. 21:15-17)
Again, this is the idea of “over all”. Christ told Peter to “feed My sheep”. This is not “your sheep in Antioch or Jerusalem” or the sheep at Rome, but essentially all of Christ’s sheep.
The previous four descriptions pertain to a certain power; that is to help souls “attain to salvation.” As mentioned, if RC is the rock and has the keys and first power to “bind and loose”, and thus if one is outside RC, then one may not be saved. The assertion has been once framed outside the Church (RC), there is no salvation.
Incidentally, RC readily admits that no Council granted this doctrine; in other words, RC is above Councils (see CCC 884).
The groups that oppose this doctrine point to a number of alternative explanations. The “rock” is not particularly Peter, but his confession of Christ. Acts 15 shows a council decision led by James, not a Petrine decision. The keys to the kingdom given to Peter were exercised when he first preached to Jew, Samaritan, and Gentile (Acts 2:14, 8:14, 10:34). Since then, the doors are open to whosoever will. The keys are no longer in use; the gates of hell will never prevail. Lastly, even if Christ commanded Peter alone to “feed My sheep”, Peter assigns this power in 1 Peter 5:2 to the elders (plural) in Asia Minor (1 Pet. 1:1). We have no other record of Peter doing so in Rome.
Also suggested above was Rome’s usage of secular authority to bolster their authority. The first example is with Constantine as guarantee of the church’s acceptance of Rome's Easter viewpoint (this eventually contributed to the Great Schism with its conflict over bread type). There are numerous other examples over time.
As mentioned, it is important to understand both sides of the doctrine; else potentially one might fall into condemnation.
So, while the basic idea of a “divine appointment” to one who preaches in and of Christ is sound, it is the next set of interpretations (rock, keys, bind/loose) where the doctrine is questionable.