Short answer: Can they do this? Yes.
Longer answer: So there is a lot of nuance here - DJClayworth has written a great answer specific to your situation, but I want to address the wider question.
In NZ (where I am), which has English Common Law as its basis, this is a fairly common scenario. If you want to do a course that will benefit the company, they will ask for a commitment.
E.g. "We will pay $5,000 for this training course, and you agree to stay with us for 12 months; if you leave before that, you will pay us back the pro-rated amount for this course"
At one of my companies, two staff members were sent on a particular training course - that was thousands of dollars, with a similar agreement - and when they left the company before the time period expired, they had to pay it back. How this was done in practice is that it was deducted from things like paying out their holiday:
So their final pay stub looked like:
Base Salay: $1,000
Holiday Pay: $2,000
Course fees: -$500
Gross: $2,500
(I'm just making numbers up)
I also took advantage of a similar offer, where it was relocating out of the main city to a satellite office - and the company paid my moving fees and I had to stay with the company for X period of time or I would get some of the costs clawed back.
However - and I think DJClayworth outlined this brilliantly - in all the above scenarios - before it was approved, I had to sign a document that outlined the terms of the offer, the start date, end date, the clawback mechanism etc.
And without such a document signed, I do not believe the company will have any leg to stand on.