If you break the law while you're doing something, you've done it illegally. Parking illegally in a wheelchair-accessible spot can mean a $300 ticket in some states.
Whether someone steals candy from a store, climbs over a fence marked no trespassing, or sets off fireworks in the grocery store, they've acted illegally. Doing something that's unkind or ethically wrong doesn't mean you've done it illegally — for that, you have to break a law. This adverb is from illegal, which is formed by adding il-, "not," to legal.