Before a spellcaster can use a spell, he or she must have the spell firmly fixed in mind...
(PHB, CH 10, Spellcasting, Known and Prepared Spells)
A question came up in play last week along these lines: "Does detect thoughts allow you to know what spells a creature has prepared?1" I was not sure if it could at all, or if it could, which degree of detect thoughts was necessary for that kind of an application. I wanted to keep playing rather than stop and look at the rule books so I made a ruling in situ.
My ruling was "the target gets to try and make a Wisdom save" and we pressed on. (Since the NPC made the saving throw, we didn't end up going any further with that).
But was I wrong? Could the PC have detected what spells the NPC caster had prepared1 without there being a saving throw involved? I am still not sure.
Can a PC or NPC detect what spells another creature has prepared1 by using the spell detect thoughts?
You initially learn the surface thoughts of the creature — what is most on its mind in that moment. As an action, you can either shift your attention to another creature’s thoughts or attempt to probe deeper into the same creature’s mind.
If you probe deeper, the target must make a Wisdom saving throw. If it fails, you gain insight into its reasoning (if any), its emotional state, and something that looms large in its mind (such as something it worries over, loves, or hates). If it succeeds, the spell ends.
Either way, the target knows that you are probing into its mind, and unless you shift your attention to another creature’s thoughts, the creature can use its action on its turn to make an Intelligence check contested by your Intelligence check; if it succeeds, the spell ends.
If knowing what spells a creature has prepared1 is beyond this spell's capacity, an answer spelling out why that is so would be very helpful.
1 The word 'prepared' includes 'spells known' for the purposes of this question, per PHB, Ch 10, Spellcasting: Known and Prepared Spells
Before a spellcaster can use a spell, he or she must have the spell firmly fixed in mind, or must have access to the spell in a magic item. Members of a few classes, including bards and sorcerers, have a limited list of spells they know that are always fixed in mind. The same thing is true of many magic-using monsters. Other spellcasters, such as clerics and wizards, undergo a process of preparing spells. This process varies for different classes, as detailed in their descriptions. In every case, the number of spells a caster can have fixed in min at any given time depends on the character’s level.