You could have a battery problem. The only way to know for sure is to try a new or preferably a known-good battery.
However, it sound more like you have a logic board or subsystem (camera/sensor etc.) problem. again, you need to rule out modular components first and when they have all been ruled out, then you can say for certain that it's a board issue.
Is this something that occurred suddenly, for no apparent reason or was it following some kind of event like a drop, coming into contact with water or repair attempt?
I would open up the phone and do a good visual inspection to see if anything is out of place or if you find evidence of water or other debris.
I would start by disconnecting all of the connectors except the battery, Dock and screen (LCD & Digitizer, do not connect the FCAM & Sensor). Plug in your phone and then check to see if the phone is more stable. If it is not, then you may have a defective screen, Dock or a Logic Board issue. If you want, you could try a new or known-good screen and Dock to eliminate the last variable.
If the bare-bones approach works, then add one flex at a time until the problem reappears and replace the defective component. I would start with the Home Button, Rear Camera, Volume & Power Button, Front Camera and Sensors.