It's because the candle doesn't burn solid wax; it melts the wax into a liquid, then boils* the liquid into a gas, then burns the gas. However it'll only boil the liquid into a gas if the temperature is high enough, and that's only possible near the flame, so it's limited by the amount of liquid wax the wick is able to pull up (through capillarity).
You can make it burn for longer or shorter by changing the wick thickness.
*it's actually a bit more complicated than just boiling; a lot of the molecules in the wax get broken by the heat into smaller and more volatile molecules (pyrolysis). But "boiling" explains it well enough for most cases.