Can a mentally ill person who takes medication regularly be a Catholic priest?
The short answer is possibly.
While Canon Law seems to indicate that it is not possible, it also allows for dispensations in this matter.
Please remember that mental health issues come in a large variety of forms. Anxiety and depression are not the same thing as being insane. Being insane is not a grave as being criminally insane.
Irregularities and other Impediments
Can. 1040 Those affected by any impediment, whether perpetual, which is called an irregularity, or simple, are prevented from receiving orders. The only impediments incurred, however, are those contained in the following canons.
Can. 1041 The following are irregular for receiving orders:
1/ a person who labors under some form of amentia or other psychic illness due to which, after experts have been consulted, he is judged unqualified to fulfill the ministry properly;
2/ a person who has committed the delict of apostasy, heresy, or schism;
3/ a person who has attempted marriage, even only civilly, while either impeded personally from entering marriage by a matrimonial bond, sacred orders, or a public perpetual vow of chastity, or with a woman bound by a valid marriage or restricted by the same type of vow;
4/ a person who has committed voluntary homicide or procured a completed abortion and all those who positively cooperated in either;
5/ a person who has mutilated himself or another gravely and maliciously or who has attempted suicide;
6/ a person who has placed an act of orders reserved to those in the order of episcopate or presbyterate while either lacking that order or prohibited from its exercise by some declared or imposed canonical penalty.
Thus we might conclude that a person with some form of mental illness may be barred from by ordained, Rome will allow one to petition the appropriate ecclesiastical authorities for a dispensation. Thus even Rome recognizes the the vast variations in mental health issues. In any case it is always most prudent to talk these matter over with competent authorities, rather than common strangers over the internet.
True that an individual suffering from some from of mental health issue must be examined carefully to see if the underlined conditions make him a suitable candidate for ordination or not. This is ultimately a question that this response can not truely answer on behalf of the Catholic hierarchy because each case must be examined on its own merits and such decisions would not be publicly announced. Exemptions could be made by Rome.
For dispensations, here is what Canon Law has to say:
Can. 1047 §1. Dispensation from all irregularities is reserved to the Apostolic See alone if the fact on which they are based has been brought to the judicial forum.
§2. Dispensation from the following irregularities and impediments to receive orders is also reserved to the Apostolic See:
1/ irregularities from the public delicts mentioned in can. 1041, nn. 2 and 3;
2/ the irregularity from the delict mentioned in can. 1041, n. 4, whether public or occult;
3/ the impediment mentioned in can. 1042, n. 1.
§3. Dispensation in public cases from the irregularities from exercising an order received mentioned in can. 1041, n. 3, and even in occult cases from the irregularities mentioned in can. 1041, n. 4 is also reserved to the Apostolic See.
§4. An ordinary is able to dispense from irregularities and impediments not reserved to the Holy See.
Although Canon 1047 does not implicitly mention a direct petition for a dispensation is allowed for these cases of mental heath issues that are not listed in Canon 1041; it does so in dealing with issues other than “amentia or other psychic illness due to which, after experts have been consulted, he is judged unqualified to fulfill the ministry properly”. Then yes, an dispensation is quite possible.