A toff who never worked a day in his life before his wife got him a job in a Bristol tv station prior politics tried to fix a split in his conservative party and took the country out of the biggest market in the world. Immigration was part of it. A greater influencing factor was Cameron's poor judgement by betting the country to fix a relatively peripheral issue of governance.
As for demographics, a distinguishing characteristic of British is they don't like being told anything by anybody. Those who remembered the days of guns and glory voted to leave. The young (who will pay the consequences), 80 per cent of London and Scotland and Ireland voted overwhelmingly to remain, a generational/regional split if there ever was one.
Pride often goes before a fall.