Why do lyrium veins heal you when the codex says they are fatal?
The codex entry on lyrium says the following:
Even though dwarves have a natural resistance, raw lyrium is dangerous for all but the most experienced of the Mining Caste to handle. Even for dwarves, exposure to the unprocessed mineral can cause deafness or memory loss. For humans and elves, direct contact with lyrium ore produces nausea, blistering of the skin, and dementia. Mages cannot even approach unprocessed lyrium. Doing so is invariably fatal.
Thus I find it baffling that touching a raw lyrium vein (as a mage no less) doesn't kill me outright, but rather heals me. I can kind of reason that raw lyrium has different properties when you encounter it in the Fade, but this also happens while underground in the Frostback Mountains.
So why do lyrium veins heal you when the codex says that they are fatal?
The codex is correct. According to the lore of Dragon Age, Lyrium Veins are fatal to mages and have adverse effects to everyone else.
There really isn't an answer as to why the veins restore your character. There isn't any comment from developers and in the wiki, it states that this happening is contradictory to the lore.
Tarkenfire's comment is basically correct - they programmed it to say Lyrium Vein and clicking on it was supposed to kill you if you are a mage but instead they made it do the opposite.