This question has always mystified me since young. For beetles, I can reason that they flip over because they have a higher centre of gravity causing them to be in unstable equilibrium when they tuck in their legs when they are about to die. For cockroaches with a lower profile, I would expect them to stay upright. But why do they flip over? Is it more comfortable for them to die this way or is there a scientific explanation for this?
As noted in some of the comments below, this is a general observation based on cockroaches being killed by insecticide. I haven't got the chance to observe (or notice) cockroaches that die in other ways and therefore do not want to limit the scope of my question to just insecticide poisoning.