Because analogWrite provides a "pseudo voltage" between 0 and 5 by rapidly switching between 0 and 5. If you analogWrite a value of 255, it's permanently on at 5v, value of 0 is off. A value like 128 is 50/50 off and on between 0 and 5, and it gives the illusion of 2.5v to the device. It's not really ever 2.5 of course, just seems like it on average. A value of say 200 is 200/250 = 0.8 so it looks like 4v
PWM = Pulse Width Modulation is the fancy name given to that technique of rapid offing and onning. As you now know, not all digital pins can do that, only the ones marked as such on the board.