My phone got factory reset and all data wiped, can I find out how? Today morning after a long taxi ride (I am travelling this week, personal vacation), I took my phone from my pocket and it seemed to be turned off. I switched it on and the phone started up as it was the first time.

All my settings, config, apps, widgets were gone. I think the phone was factory reset. Not sure if it was locally (accidental click in settings?) or may be remotely. (The phone was fine earlier in the morning). 

I tried to get the data from my Google account backup (which I remember setting up when I got this phone) but I could not (no 'Restore' option was enabled in settings. But that would be a different question).
I had to manually (painfully) set up things again. All my photos are backed up to google and I think I can get them back. Same for apps, most of the should have data on the cloud somewhere. 

Is there a way to know what happened?

I have a HTC one (M7), and use Google for most services including backups.
Well, I don't think you could get to know what has made your device getting factory reset on its own. As far as I know I think somehow the volume up and power keys may have been pressed which results in factory reset. I have also heard the if you put the patter lock wrong over the HTC M8 for more that 10 times, the device gets automatically factory reset. I am sure Accidently you may have !!