There were two reasons that this referendum happened
1. Cameron thought it would placate the Ukip side. He didn't take into account the collapse in the labour vote to Ukip as well and also the destruction of the Lib Dems
2 He didn't think he'd win a majority.
So tactical voting for Ukip tactically got us a referendum.