This is due to a specific feature of the AVR microcontrollers, where the same register (PORTB, PORTC or PORTD) is used for controlling both the output value of the pin and its optional internal pullup resistor. The command digitalWrite(pin,HIGH) sets to 1 the bit of this register corresponding to the selected pin.
If the pin is set to INPUT (which is the default), the effect of digitalWrite(pin,HIGH) is to turn on the internal pullup.
If the pin is set to OUTPUT, the same command sets the output to HIGH.
The internal pullup is about 30 kΩ, which lets flow a very small current through the LED. You may notice that the voltage at the pin is 5 V if nothing is connected to it, but significantly less when the LED is connected. Notice also that the preferred way of enabling the pullup is pinMode(pin,INPUT_PULLUP).