I have had this very thing happen to me at my last job, in both directions. Once I was paid nearly three times my normal amount and next two checks were almost nothing to compensate. And another time I was short-changed and they made it up to me later with a tiny bonus to apologize.
It is legitimate for the company to recover the funds, even it seems unfair to you. But think of it from their perspective, that it might seem unfair if you were to refuse to give back the overage.