First off, this is my first bug report for BG3, so apologies if I don't follow a template. Lemme know if you need additional details.
I was able to cast Detect Thoughts in dialog, but I didn't actually know the spell. I had just hit Level 3 on my Bard but had not yet gone through the Level Up screen to choose spells and subclass.
I was in the Druid Grove, talking to the child Tiefling vendor (Mo?) and a second child was attempting to pick my pocket. I had to pass a Perception check before dialog started, but then I think there was an option right away that started with "[Detect Thoughts]" or something.
I definitely have a save game a couple moments after this happened with my character concentrating on Detect Thoughts but not having the spell in my spell book. I may have one from right before as well.