In my experience cheap lights die, and some more expensive designs are prone to failure. Bike shops sell cheap lights because that's all some people will buy, and better they have a dodgy light than no light (there are enough cyclists without lights already).
All the factors you list come down to one or two factors, depending on whether you consider "built to an excessively low price point" to be a factor. The other is poor design. It's not easy to make a bike light that works, and doing so costs money. If you search for bike lights on kickstarter those projects often document the design and testing (which is one of the few places you can read about it).
I've had lights intermittently turn themselves off while riding, and that's either something hitting the on-off button or the batteries momentarily disconnecting when bumped. Rather than reproduce the latter I prefer to add conductive spacers with the batteries and see whether that solves the problem - add a chunk cut from a tin can or 5-10 thicknesses of aluminium foil at one end of each battery.
I expect to pay ~$40-$60 in Sydney for a decent rear light, maybe $30 online, and if they don't last at least a year I take them back. And I do take them back. Maybe 5% fail within a month. For front lights I pay the same as a rear one for a blinky, ~$100 for a "to see by" light. But I also DIY and use dyno lights (more expensive up front, heavier, but cheaper in the long term).
This is easier if you're running multiple bikes, whether for yourself, your household, or your group of friends. Or you have a decent LBS. Buy 2-3 different lights to test, pick the one you all like the most and buy one (or more ) each, plus a couple of spares. That way you know you're getting something that works, and have a communal spares pool. You can get a similar effect by buying what everyone else has. But buy exactly what they have, a lot of bike lights look very similar and a cheap clone is not the same as the real thing.
I have lights regularly last until the LEDs are so dim the light is worthless. Specifically, I have a box full of "bike lights and bits" in the garage that contains 5-10 rear lights and 3-4 front ones, none of which I would use today as my primary light (I use them on trailers and take them to group rides to lower the suicide rate). The front ones I expecte to fail, white LEDs have a finite, short life that in a "every weekday in the winter" light means 2-3 years. Rear ones mostly just fall to the progression in LED efficiency, in that "the same" light bought next year will be noticeably brighter (front ones too, obviously).