Can I connect pins to high voltage?

Do not do this, it will damage your board.

If you want to switch 12 or 24V, you must use a transistor or relay. I would recommend a bc337 transistor, if the led current is only a few hundred mA, but there are many others you could use. You will need a resistor for the transistor's base pin (e.g. 4K7) as well as led series resistor.

But why do you want to use 12V to light your led?