The UK didn't want unlimited immigration from the EU, and the EU refused to even consider the possibility of an exception, so the UK left.
It's not complicated, it's old history, and the fact that people are still describing this as "brits dumb hurhur" is racist and abusive. The idea that it could have got an exception, by the way, is yet more federalist lying. Cameron did a tour around Europe directly visiting member states, begging them to grant such an exception, and they refused. He returned with his "deal", presented it to the country and never mentioned it again during his campaign because it was an insult to the concerns of the voters.