If a person, including any corporation, partnership, limited-liability company, or any other legal entity has gained money or property through the commission of any violation involving an illegal residential occupancy or an illegal over-occupancy of a dwelling, then, upon conviction thereof, the court, in lieu of imposing the fine authorized for the offense under this Code, may sentence the defendant to pay an amount, fixed by the court, not exceeding double the amount of the defendant's gain from the commission of the offense, as such gain is reasonably determined by the court.