In the Catholic Church, what makes something illicit vs. invalid? From this question, Why can't the laity preach a homily, and can a lay person ever preach?, in the Catholic Church, what determines the licitness vs. the validity of something.

Please give examples.
The illicitness and the validity of Sacraments are canonical terms used to describe the effectiveness of the sacrament.

Illicit means, roughly, “illegal”.  In the case of a Sacrament, it means performed in a way that is not permitted by the rules or laws of the Church. (But the sacrament did happen). The term Illicit can also be used to refer to actions not done in accordance with the established norms.

Invalid means the Sacrament didn’t happen at all. There is some defect in matter, form or intention. Question of validity occurs only for a Sacrament.

In the example you have pointed out, in giving a homily, there is no question of validity as there is no Sacrament. But it is illicit because it is against the established norms of the Church.

Examples:

Licit and valid: Mass performed by a priest in Good standing with the diocese.

Illicit but valid: Mass performed by an excommunicated priest Or priestly ordination of men without papal approval.

Invalid: Mass performed without proper form, matter or intention. Or an attempt at priestly ordination of women. Please note that all invalid sacraments are Illicit.

More generic example: If you steal money from a bank the money is illicit. If you print your own money the money is invalid.

In a different perspective, in an invalid sacrament Jesus is not present. But in a illicit (but valid) sacrament Jesus is present, but he is not happy about that.