Manual flip might be the problem, it has failed to detect the angle whether to capture image as front facing or just the angle where it has stopped during manual flip, Try clearing the system app "Caliberate Camera Angle" this should solve the issue. or make sure the camera flipped, if you are doing it manually.
Yes. We unnecessarily speculate on something that the author of the original query should have correctly specified and described in advance... If selfie is occasionally upside down and with inverted colors, it's probably a hardware problem with the camera cable.