It can be a few things.
- An app that is causing it
- The rom that is causing it.
- A hardware failure
- Or you battery.
What I would do is a full wipe and then reflash the rom. If the problem is still there then try a different rom (non aosp).
If the problem is still there then it's a hardware failure. My guess is that your battery is damaged. Is your battery swollen? If so, then buy a new battery.
Samsung Galaxy S 4 I9505 | WanamLite v3.0
Samsung Galaxy S II I9100 : AOKP 4.2.1
HTC Touch Pro2 | ROM: Valkyrie 6.5.23115TR2.5
HTC HD2 | DarkStone1337 [FroyoStone Sense - V3.2]
HTC Desire : Oxygen v2.1.3