When an iPhone cannot maintain power the most commom culprit is the battery. But it could be any component of the iPhone Power Management Circuitry. Also battery is a cheap and easy place to start trouble-shooting. For your Warranty covered iPhone 5, first step would be to Restore iPhone with iTunes 10.7 or 11 on computer. See if better. If still problem, make Genius reservation and take to Apple for resolution under Warranty.