The distinction between the terms lies in the laws of that particular jurisdiction. Legality has to do with the detail of laws. There must be a formal command in writing, passed by legislative authority, such as local or national government, that makes it illegal. Illegal also has another common usage in English.
It is used when referring to the sanctioned rules of a game, such as football or soccer. On the other hand, something that is unlawful goes against the established law without there being a specific law that has been put into action or practice.
For example, you would get into trouble if you accidentally tossed a lit cigarette into a trash can, and it caught on fire, and there was damage. It may have indeed been an accident, but you still caused harm and endangered people who were nearby. Something illegal is prohibited, while something unlawful breaks the unspoken rules of society.