"Can a company fire an illegal immigrant for being illegal?"
Absolutely. An illegal immigrant does NOT have authorization to even be in this country, much less work, and if the employer becomes aware of that and does nothing, the company is subject to both penalties (of up to $10,000 per day if I recall correctly) and jail time.
Assuming the employer complied with I-9 requirements when the individual was hired, it also means the person presented fraudulent work authorization documents. Falsifying information alone is sufficient to provide "good cause" to terminate someone.