Unlawful, illegal, illegitimate, illicit are comparable when they mean contrary to, prohibited by, or not in accordance with law or the law. (Otherwise than this negation in character, the words in general carry the same differences in implications and connotations as the affirmative adjectives discriminated at LAWFUL ).
But there are a few recognizable differences.
Illegitimate tends to be more narrowly used than legitimate ; its most common application is to children born out of wedlock or to a relation which leads to such a result, but it is occasionally referred to something that is not proper according to the rules (as of logic) or to the authorities or to precedent.
Illicit is used much more widely than illegitimate ; it may imply a lack of conformity to the provisions of a law intended to regulate the performance, the carrying on, or the execution of something that comes under the law of state or of church, but it is also applied to something that is obtained, done, or maintained unlawfully, illegally, or illegitimately.