H1B Extension Cost Reimbursement

I got my H1B renewed last year around October and quit my company in April this year. The company has sent me a letter asking reimbursement of H1B related cost of $5000.

Can someone advise on it? Is it not illegal to ask employee for H1B expenses?

Usually, it is not legal. But, it all depends on the contract you have signed with them and understanding…
Some of that are just general contracts…Talk to your company attorney and see the clauses, if you have signed any of them.