There are a number of related questions here.
The Bishop of Rome
The Bishop of Rome (i.e., the Pope), being the universal pastor of the Catholic Church, may celebrate in any rite he wishes at any moment.
There is not a specific norm in the Canon Law (abbreviated CIC)—the law for the Western church—or the Code of Canons of Oriental churches (abbreviated CCEO)—the law for the Eastern churches), however Canon Law says,
The bishop of the Roman Church, in whom continues the office given by the Lord uniquely to Peter, the first of the Apostles, and to be transmitted to his successors, is the head of the college of bishops, the Vicar of Christ, and the pastor of the universal Church on earth. By virtue of his office he possesses supreme, full, immediate, and universal ordinary power [potestate] in the Church, which he is always able to exercise freely (CIC Can. 331; see also CCEO Can. 43).
The power (potestas) would include the license (permission) to celebrate the Sacraments in any rite.
There is also no restriction according to membership in a particular church as to who can be elected Pope: any bishop (indeed, in theory, any baptized, unmarried Catholic male) may be elected Pope. (If he is not a bishop, he would need to be ordained a bishop before he could become Pope.) CIC 332 says,
The Roman Pontiff obtains full and supreme power in the Church by his acceptance of legitimate election together with episcopal consecration. Therefore, a person elected to the supreme pontificate who is marked with episcopal character obtains this power from the moment of acceptance. If the person elected lacks episcopal character, however, he is to be ordained a bishop immediately (CIC 332§1).
Note that the CCEO uses precisely the same language in Can. 44, and that neither one makes a distinction among members of a particular church.
(As a historical note, Cardinal Grégoire-Pierre XV Agagianian, the Patriarch of the Armenian Catholic Church, was a serious contender for the papacy in 1958. See the corresponding Wikipedia article.)
Bishops and priests
The situation for bishops (other than the Pope) and priests is a somewhat more restricted.
Priests and bishops (those who do not otherwise have restrictions placed on them) are, of course, always able to celebrate the Sacraments according to the rites of their own Church: the Roman Rite (and some of the smaller rites in a few places, such as the Ambrosian Rite in Milan, Italy) for Western priests, and the rite of whichever church they belong to, for Eastern priests.
In general concelebrating in the Mass or Divine Liturgy of a rite that is not one’s own is allowed, provided the liturgical norms of the given rite are being followed and there is no syncretism (CCEO 701). (Priests and bishops, however, are never to concelebrate with priests or bishops not in communion with the Catholic Church, even if they are validly ordained—e.g., the Eastern Orthodox. See CCEO 702.)
For other cases, the bishop in charge of a diocese can give permission for priests (or bishops) of a different rite to celebrate the Sacraments in the bishop’s own rite, within his own diocese. (Actually, the bishop could grant permission to celebrate in any rite, but there is seldom any need to grant it outside his own rite.)
Evidently, the Pope himself, or else the patriarch or major archbishop of an Eastern church, could also grant that permission.
It should be noted that, because the Latin Rite is so ubiquitous, and often less difficult to learn, it is generally easier for Eastern priests and bishops to be given permission to celebrate in the Latin Rite than vice versa.
See “Celebrating in an Eastern Rite” by Fr. Edward McNamara, L.C., and the followup article.
Note that, although bishops and priests should in general follow the rites of their own particular church in all the Sacraments, the faithful may freely receive the sacraments from any Catholic priest or bishop.
Of course, the Sacraments of Initiation—especially Baptism and Confirmation/Chrismation—should generally be done in one’s own church, but one may receive them in a different rite if a pastoral necessity arises. (For example, it is common for Eastern-rite Catholics to live in an area with no Eastern parishes nearby. In such a case, they could request to have their children baptized and confirmed at the local Western-rite parish. They would, however, still belong to their respective church.)
(As a side note, the Eastern churches technically do not celebrate Masses. They call their celebrations of the Eucharist Divine Liturgies. The term “Mass” comes from the Latin words of dismissal Ita, missa est, that are said by the deacon or priest at the end of every Mass—save the Mass of the Lord’s Supper on Holy Thursday—that is attended by faithful.)