This question is mainly applicable to beetle's and cockroaches. If I flip them so their legs point upward, they usually squirm around and wiggle trying to come back upright. Sometimes they succeed, and turn right side up again; sometimes they don't. Do insects have any built in mechanisms to unflip themselves.
I was unable to find any sources, but I believe they should, since insects climb stuff, and they may land inverted if they fall, so a mechanism might've been evolved to unflip themselves.