In the case of an incandescent lamp, temperature of the filament is everything. It needs to run hot in order to produce light. Keeping the heat energy produced by a current running through a resistance is desirable since the more energy retained, the less power needed to heat the filament to its desired temperature (around 2500 K depending on the lamp). There does need to be a heat loss mechanism however to stabilize the filament temperature. Otherwise, its temperature would continue to rise as more electrical power is dissipated, and at some point, it would melt. A bulb with a partial vacuum serves this purpose, plus it prevents oxygen from reaching the hot filament which would destroy it through oxidation.
In the case of an LED, somewhat more of the electrical energy goes to visible light than with an incandescent device, however, there is still a portion which transforms to heat. Heat is detrimental and not at all desirable for an LED so there needs to be a means to get rid of as much of it as possible, hence the fins. To produce an equal number of lumens (i.e., light) as an incandescent, the LED requires less power, but it is not 100% efficient at converting that to light, so a cooling mechanism is always needed. For small, instrument type LEDs (with milliwatts of power), just the package accomplishes this, but for lighting LEDs where watts are involved, it has to be facilitated with a heat sink which can transfer the heat to the surrounding air. At high altitudes (or in a vacuum) this transfer may not be as efficient, and if some other means of cooling is not provided, LEDs can self-destruct.