If you look at any character’s spellbook you might notice that there is a fuzzed-out magic type labeled ELDRI (Eldritch). This is a special magic type that cannot be naturally learned by any class, and you cannot Scribe spells to it (shown by black and red spellbooks with pentagrams) while the type is fuzzed out. It might be worth mentioning that there are Spellbooks that contain non-Eldritch spells that are blocked from Scribing until you unlock Eldritch. Not sure if that is a bug or not.
To unlock it, you have to ask certain NPCs about ELDRITCH (ELDRI does not work). Only the characters in the party at the time you ask will get it unlocked. Once you have asked an NPC about it you cannot unlock it from them again. Any characters you pick up afterward will not be able to use it unless you ask another NPC with Eldritch knowledge.
As for the “where,”, There are two NPCs in the early game that can unlock it for you: Magus Trimestes in the Bronze Cauldron, and Mistral if you choose to resurrect him. There are a few others later in the game as well.
Once you have it unlocked you can attempt to Scribe Eldritch Magic, but know that; Characters who attempt it can be inflicted with Insanity. It is easily cured, but you will probably want to be near a Safe Haven before you try it, just to be safe.