How does an iOS device keep time when it is out of power?
The iPhone is not completely depleted when the battery "dies."  If you'll notice, when you try to turn it on when the battery is dead, the screen will come on briefly to tell you the battery is dead -- i.e., there is still some energy left in the battery.  The clock continues to run off of the battery, and takes such a small amount of energy that Apple decided to keep the clock going.

Eventually, the battery will completely die (probably after many days or weeks), and the clock will eventually stop keeping time.  As Ian C. mentioned, the clock will synchronize when the phone does get plugged in and turned on again, if a network is available.