I was working for a cash and carry company until 30 august. They terminated my employment. Since terminating my employment they have sent me a letter saying I was overpaid by £507.21. Am I legally obliged to repay them the money.
Yes you are legally obliged to return the money, especially if you know you have been over paid - have you worked out whether the over payment is in-fact an over payment or not using your own calculations?
Money paid to you in error is not yours (this is a long established legal fact in the UK, but my answer is not legal advice), and if you keep it then you can be prosecuted for theft.
I suggest you contact your former employer to offer to return it now.