This is a complicated issue, but generally, there were three factors, I think. First, there was a belief in the United Kingdom (UK) that membership in the European Union (EU) was costing the UK money best spent at home, second, there was a misunderstanding about how the EU operated such that some people in the UK believed that they had no representation in the EU's functioning, and third, there has been a rising nationalism rooted in xenophobia in the UK (and other countries), which has been strongly exacerbated by all of the people who are fleeing their war-torn countries and heading for Europe.
Last year, the UK gave the EU far more than it received back from the EU in benefits, approximately 8.5 billion pounds. The UK could have used that money for many other government functions, for its national health service, for instance, or for its social safety net. There was a great deal of resentment on the part of many people in the UK, particularly those who were not doing well financially, and the thought of "subsidizing" other peoples did not sit well with them, a kind of "Charity begins at home" mentality. This might not seem too unreasonable, but the stability and security of the UK is certainly dependent to a large degree on a stable Europe, so draining off that sum of money annually could create problems that would affect the UK.
As evidenced by the fact that millions of UK people Googled to find out more about the EU (after they had already voted on "Brexit"), many people in the UK believed that the EU had some sort of ruling body that citizens from the UK had no say in choosing. The fact is that representatives to the EU are elected by their respective countries, so this objection was based on a complete misunderstanding. Nevertheless, this misunderstanding seemed to resonate more strongly than the facts, so this formed another reason to want to leave.
Immigration that many believe allows terrorists into the EU countries has played a significant role in the UK's wanting to leave, immigration that has nurtured an increase in nationalism and a dislike or even hatred of "foreigners." One of the whole points of an EU was that people could come and go across borders freely, such that in the long run, it would be one big happy family in that part of the world, with ancient enmities dissolving in the mix. Right now, though, many European countries are overrun with fleeing immigrants, because of the war in Syria, because of ISIS, and because for many people in that part of the world, life is hell. These people have cultures and religions usually significantly different from those of the western world. Assimilation has not been smooth. And the refugees need a great deal of help from the EU countries. Add to that mix the fact that these people are coming from areas with a terrorist presence, and it is easy to see that anyone even slightly nationalistic and slightly xenophobic is unlikely to be feeling hospitable. In the opinion of those people, the only way for the UK to really control this problem is to leave the EU.
I do not want to imply that all of the reasons that people in the UK wanted to leave the EU were unreasonable, but it does seem to me that few people did enough investigation into the situation, to see if their reasons were based in fact or in rabble-roused opinions, and it seems fairly clear now that the vote has been taken, there is a great deal of buyer's remorse.