Flexible statistical inference for mechanistic models of neural dynamics