Generally, I'm the DM, so I would come up with the answer if needed. If it mattered to my character, I would ask the DM and hope that they came up with something. It doesn't have to be prepared ahead of time. I just don't want an answer founded in gamism, as I mentioned above.
I get you, but I think that generally where you see people answer with "gamist" answers, is because they often find that the bolded parts don't come up (for them), so they don't bother to do the story-work.
If an NPC casts a spell or ritual that is unknown to the PCs, it is VERY LIKELY because they have 1) an unusual nature; 2) did some serious research; 3) had it granted by some unique source; 4) on and on, all of which are "rare" and "unusual".
Wouldn't the answer, by the very nature of the story being told, almost always be, "something you'll never find out"? I mean, if the information was readily available (like say, could be found within the timeframe of a PC's downtime), wouldn't it be available to them? If it is not, then by its nature, it most often will be something they can't learn.
Like "two years of practice; AFTER you know where to find the information how; AND have sacrificed an elf child; under the light of a specific comet;" (or whatever - I mean, my point is that this would be so very campaign specific, if bothered with at all, that I can't even really make a good example of it).
Point is, the answer would nearly always be "Magical Secrets". IE Stop adventuring and pursue it (and only it) as a career if you really care how they did it. Then MAYBE you'll figure it out.
"Or we could just play THIS adventure instead."