Hi I think they are legally able to do this from my understanding of EU law. It sucks especially if you have had to relocate for the job but you obviously were not enjoying working for them. It sounds as if the lead dev might be feeling overprotective of his own work and does not want to let go.
I am sure you will find another job easily enough as good devs are in demand. Hopefully at a place where you are valued and can contribute your skills