Hi,
It does this because there are a couple things in particular about an op amp and the nature of the capacitor that causes this to happen.
The op amp has its non inverting input connected to ground, which is like a reference terminal. The input voltage to the circuit is referenced to this terminal so that any voltage on the input is converted into a current flow through the resistor. That current is:
I=Vin/R
Now an op amp has a feature about it that allows it to generate a current between the output and the inverting (-) terminal. That current is equal to the current it gets into the inverting terminal except of opposite polarity. Since the input current is I, that means the current between the output and the inverting terminal is -I, which has to flow through a capacitor because that's all it has in the circuit between the output and the inverting terminal. If the input current I is constant, then the current between the output and inverting terminal will also be constant as long as the op amp operates within its limits.
Now the second principle here is that when a capacitor has a current flowing through that is constant the capacitor ends up with a voltage across it that is a ramp, so the voltage increases (or decreases) with time. That's how a capacitor responds to a constant current and that's just nature.
A third principle is that when the op amp is operated within it's limits, the inverting terminal voltage is kept equal to the non inverting terminal voltage. This is a concept known as "Virtual ground". This is just one aspect of the way an op amp works.
So we have a constant current input, and by nature of the op amp we have a constant current between the inverting terminal and output, and by nature of the capacitor we have a ramp voltage appearing across it, and by the concept of virtual ground we have the inverting terminal voltage equal to the non inverting terminal voltage, and since the non inverting terminal voltage is zero that means one end of the cap is at zero volts so the other end is ramping up or down, and that voltage appears at the output.
In mathematical terms this is known as an integrator. The output is equal to the time integral of the input. Since the integral of a constant is a ramp, we see a ramp output. If we instead vary the input instead of keeping it constant, the output is still the time integral of the input but it wont be a ramp anymore because the time integral of a varying quantity is not a ramp.
There are limitations to this though. If the input current is too high the op amp may not be capable of putting out enough current to keep the feedback current equal to the input current, and if the output voltage goes too high or too low the op amp may not be able to put out the required voltage due to power supply limitations and losses within the op amp output stages.
In addition to those limitations of the input and output levels, there is also a limitation in time that comes about because of the speed of response of a real life op amp. If the op amp can not force the output up fast enough to keep up with the required speed, the ramp will not rise as fast as it should for a given input and capacitor value. This limitation is known as the "Slew Rate" of the op amp, and the effect is similar to a perfect op amp that already has a small capacitor and resistor inside of it...any attempt to rise faster than those values will allow will result in these equivalent components limiting the output rise time. For example, if the op amps slew rate is 1v/us and we try to create a ramp that rises 2v/us it wont work because the internal structure of the op amp prevents it rather than the external components.