In theory at least, any unmarried, baptized Catholic man can be elected pope; I say "man" because canon law requires that anyone elected pope be immediately consecrated as a bishop:
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.
(Code of Canon Law, canon 332, section 1; emphasis added)
Of course, to be ordained (consecrated) a bishop, one needs first to be a priest:
In regard to the suitability of a candidate for the episcopacy, it is required that he is ... ordained to the presbyterate [i.e. the priesthood] for at least five years.
(Canon 378, section 1)
Which then leaves us with the question of why only men may be ordained to the priesthood. A discussion of this question is not found in the Summa Theologica proper, but it does appear in the Supplement to the Summa, which was compiled shortly after Aquinas' death by one of his students. After a brief discussion, Aquinas' student concludes that those who are called to become priests receive spiritual power over others, and it is not possible for women to receive this kind of power, "for a woman is in the state of subjection" (Supplement to the Summa Theologica, Question 39, Article 1).
Well, we know better today, one might say. So, Catholicism, what else you got?
Inter Insigniores, a statement on the subject issued in 1976 by the Congregation for the Doctrine of the Faith, comments:
The bishop or the priest in the exercise of his ministry, does not act in his own name, in persona propria: he represents Christ, who acts through him: "the priest truly acts in the place of Christ", as Saint Cyprian already wrote in the third century. ... The supreme expression of this representation is found in the altogether special form it assumes in the celebration of the Eucharist ...: the priest, who alone has the power to perform it, then acts not only through the effective power conferred on him by Christ, but in persona Christi, taking the role of Christ, to the point of being his very image, when he pronounces the words of consecration.
Because of this symbolic role,
the priest is a sign, the supernatural effectiveness of which comes from the ordination received, but a sign that must be perceptible and which the faithful must be able to recognise with ease. ... when Christ's role in the Eucharist is to be expressed sacramentally, there would not be this "natural resemblance" which must exist between Christ and his minister if the role of Christ were not taken by a man: in such a case it would be difficult to see in the minister the image of Christ. For Christ himself was and remains a man.
one must note the extent to which the Church is a society different from other societies, original in her nature and in her structures. The pastoral charge in the Church is normally linked to the sacrament of Order; it is not a simple government, comparable to the modes of authority found in the States. It is not granted by people's spontaneous choice: even when it involves designation through election, it is the laying on of hands and the prayer of the successors of the Apostles which guarantee God's choice; and it is the Holy Spirit, given by ordination, who grants participation in the ruling power of the Supreme Pastor, Christ (Acts 20:28). ... For this reason one cannot see how it is possible to propose the admission of women to the priesthood in virtue of the equality of rights of the human person, an equality which holds good also for Christians.
Thus John Paul II was only echoing the consistent teaching of the Church in his 1994 Apostolic Letter Ordinatio Sacerdotalis. He discussed, as well, the fact that Christ Himself appointed only men as his followers. He says:
In the Apostolic Letter Mulieris Dignitatem, I myself wrote in this regard: "In calling only men as his Apostles, Christ acted in a completely free and sovereign manner. In doing so, he exercised the same freedom with which, in all his behavior, he emphasized the dignity and the vocation of women, without conforming to the prevailing customs and to the traditions sanctioned by the legislation of the time."
That is, Christ was not bound by the customs of his time in his interactions with women in general, nor in the importance and dignity he afforded them; thus, the fact that he did indeed choose only men as His apostles and those closest to Him must mean something.
These men did not in fact receive only a function which could thereafter be exercised by any member of the Church; rather they were specifically and intimately associated in the mission of the Incarnate Word himself (cf. Mt 10:1, 7-8; 28:16-20; Mk 3:13-16; 16:14-15). The Apostles did the same when they chose fellow workers who would succeed them in their ministry. Also included in this choice were those who, throughout the time of the Church, would carry on the Apostles' mission of representing Christ the Lord and Redeemer.
Pope John Paul II concludes:
In order that all doubt may be removed regarding a matter of great importance, a matter which pertains to the Church's divine constitution itself, in virtue of my ministry of confirming the brethren (cf. Lk 22:32) I declare that the Church has no authority whatsoever to confer priestly ordination on women and that this judgment is to be definitively held by all the Church's faithful.
The phrasing "this judgment is to be definitively held by all the Church's faithful" is significant. It is precisely this phrasing that must be used in statements which are to be considered infallible.
Nevertheless, because it was not obviously a statement "regarding faith and morals", but apparently limited to an ecclesiastical practice, there was much discussion after the pope's statement about whether or not this statement should be considered infallible or not. (As could be expected, those who favored, or were at least open to, the ordination of women tended to believe that it was not infallible; those who were opposed tended to believe it was.)
Finally, in 1998, the Congregation for the Doctrine of the Faith wrote a commentary on another letter of the Pope regarding what matters were and were not to be held definitively by all Catholics. This commentary had to do with the three-paragraph Profession of Faith to be made by certain Catholics occupying ecclesiastical offices. The Profession contains a paragraph stating:
With firm faith, I also believe everything contained in the word of God, whether written or handed down in Tradition, which the Church, either by a solemn judgment or by the ordinary and universal Magisterium, sets forth to be believed as divinely revealed.
The Congregation states that the teaching on limitation of ordination to men comes under this paragraph:
The Supreme Pontiff, while not wishing to proceed to a dogmatic definition, intended to reaffirm that this doctrine is to be held definitively, since, founded on the written word of God, constantly preserved and applied in the Tradition of the Church, it has been set forth infallibly by the ordinary and universal Magisterium. As the prior example illustrates, this does not foreclose the possibility that, in the future, the consciousness of the Church might progress to the point where this teaching could be defined as a doctrine to be believed as divinely revealed.
Thus, the brief answer to your question is:
Because Jesus was a man, and chose only men as his apostles, only men can be ordained; and because only men can be ordained, and popes must be ordained, only men can become popes.