He had no choice but to resign IMO. He had led the Remain campaign and it was rubbish. He had been defeated and he would have been kicked out in a no confidence vote at some stage.
You have to remember at the time people were shouting very loudly for a Scottish referendum and Brexit. He delivered both. Some very vocal people just didn't like the results. hence why it's still a divisive topic today.
As another poster pointed out in another thread (
@thewittowoo ) , Cameron was not expecting a win in the 2015 election. He was probably thinking another coalition with the Lib Dems who would have vetoed the referendum and he'd have been off the hook.
The way I look at it is, Cameron was voted in on a manifesto for a Brexit referendum, The referendum was won by leave. May was voted in on a leave manifesto. Boris was voted in with a ridiculous majority on a totally 'get Brexit done' campaign. The country essentially voted at least 4 times for Brexit. As a remainer myself I cannot ignore that fact and accept it no matter what I think of the consequences.