These answers pretty well cover several of your options, but I'd like chip in a few others.
Targeting
As others have said, be aware of how the spell is cast. You must be within 30' of your initial target, must have line of sight on an initial mind-reading target, then must use an Action to switch it to a new target. OR you may scan for thoughts within 30' of you and use an Action to pick one of those thought sets to chose from
So, you have three options here.
1: You cast the spell, involving speech, gesticulation, and a copper coin within line of sight of your target. This is super suspicious. And will probably end in combat or summoned guards. And, however it pans out...the spell will have expired by the time things calm down.
2: You cast the spell outside the line of sight of the target, then move to within line of sight and shift the spell, this burns a round of time (I'll get to that in a second.) Assuming it only takes you 1 round to get into line of sight of the target. And, bear in mind, someone else might see you casting and freak out. I'd be calling for stealth checks here if they were in a populated area.
3: You cast the spell outside the line of sight of the target, then attempt to hone in on the thoughts of your target without moving into line of sight. The catch here is, you detect every intelligent creature within 30' and have to pick which one you want to focus on, consuming an Action. This includes your allies and any bystanders, and the spell does not give you any information about the intelligent creatures besides 'they are within range of the spell.' You don't even know which direction they are in. If this is how they are doing it, determine how many people are within range of the casting, and roll the dice to see if they picked the right person.
Time
The spell lasts for 60 seconds. 10 rounds. Most conversations last significantly longer than that. And unless they cast the spell directly on the target (requiring line of sight) then they burn 6 seconds to take a round and Action to switch the spell to their desired target. So, more likely, they can Detect Surface Thoughts for 54 seconds.
So, have your NPCs engage in small talk...like actual people would. If the players try to push them straight to the topic, feed the person reading their mind thoughts about how rude they think the players talking to them are...and allow that to run a risk of the NPC refusing to talk to them further.
In social interaction, 60 seconds is not a long time. Particularly if the players cast the spell before trying to start the conversation. Have the NPC putter around their shop for a bit before coming to talk to them...have them be already talking to someone else when they arrive...have an interruption occur (such as someone else entering the shop). Anything that eats up time. They are taking a gamble by casting Detect Thoughts that the relevant topic will be discussed within 60 seconds. This isn't an interrogation where you just start demanding answers...and if they treat it like one, I'd expect no one to want to talk to the players next time they are in town.
Obviously, don't abuse this...let Detect Thoughts work sometimes. Otherwise you'll just frustrate them. But it shouldn't be the all-solving-hammer they are currently using it as.
Hard Counters
If you have a villain, you want to block this, especially if they are going to deceive the players directly. For this, you need hard counters that absolutely block mind reading. You have a few options...
The obvious option here is Mind Blank. You are immune to mind reading. Period. They try to read your mind, and get nothing.
Next is the 17th level Mastermind-Archetype Rogue's ability, Soul of Deceit. They can block attempted mind reading with ease, or even roll Bluff to present false thoughts to attempts to do so.
Creative use of Modify Memory can bypass this. The villain could temporarily alter their memory (leaving a written note to tell them to undo the spell later) to believe they are telling the truth. Thus, 'Detect Thoughts' would accurately pick up on false information.
Mordenkainen's Private Sanctum shuts down Detect Thoughts entirely...one of the options is that no creature inside the Sanctum can be targeted by a Divination spell. You could even play this off as the other person casting or entering an area under the effect of the spell to 'make sure their conversation remains private.' The RAW allows for permanent versions of these...so a wealthy non-magic user could very well have a permanent Sanctum set up for private conversations.
Nondetection is probably the lowest level method of a hard-block. It makes the target immune to Divination spells (and, again, Detect Thoughts is a Divination Spell).
And, of course, Detect Magic would go off if a player using Detect Thoughts entered the caster's range. It wouldn't tell them specifically what you were up to, but they would know you were using a Divination spell in their presence.
Non-Spell Countermeasures
Misinformed NPC. Have the character providing the information be entirely honest and truthful...but the information they give was provided by a deceptive source, so the NPC in question is honest...but wrong. The players may be able to use DT to be immune to manipulation, but the NPCs they talk to certainly aren't.
Pathological Liar. A character like this would probably think about several different 'answers' to their question with no distinction as to which one was true. You know they probably aren't telling you the truth...but good luck figuring out which of their thoughts was the truth.
Superfluous information. People's brains hop around all the time. Don't just give your players the relevant information..dump that NPC's whole stream of consciousness on them. Thinking about what's for dinner, wondering if these adventurers will shut up and buy something, grumping about that spider web they just spotted over your shoulder (I just swept the corners, dangit). Sure...they might get the info they are looking for, but they'll have to dig through a bunch of extra crap to find it.
Hopefully this helps out a bit
There are no rules that would explicitly provide a way to do this, because D&D doesn’t want to make a stand on whether or not classes are things that characters are aware of and know themselves. Some things—paladin oaths, warlock patrons, etc.—are pretty explicit and obvious, but others, particularly fighter and rogue are very generic and can lend themselves to a wide variety of characters, occupations, and fighting styles. There is no particular reason why they would necessarily see any commonality between them.
Which therefore means that class may not be a thing to know. That may, depending on your campaign, be purely metagame information. It’s entirely plausible, in fact, that even things like oaths and pacts are not as neat and consistent as laid out in the books, but rather more unique to the individuals involved. It is very reasonable for, say, a sorcerer/warlock to say that all of their power comes from the patron, just that it’s a different sort of pact than a pure warlock has. And so on and so forth.
Since D&D doesn’t want to dictate how any given table handles this, they cannot write mechanics that rely on it being “real” in-character information, so no such detection spell could be written.1 If classes are real, known concepts within your campaign, you will have to ask your DM for details on how you can know and recognize them in character.
- This applies to a lot of things in D&D, and always has, though 5e is arguably trying to go farther with it than other editions. However, they aren’t doing so perfectly—while they often say they support a variety of playstyles, they sometimes seem to forget that and write mechanics that presuppose one particular style. But this is one particular case where they haven’t done that, and personally I suspect they won’t.
Best Answer
It's up to the DM
Even when casting detect thoughts on a conscious creature, the thoughts that are detected at both the initial level and at the deeper level are entirely up to the DM. The spell gives guidance on the types of thoughts, but the DM will determine what specific thoughts are
for the initial cast. Whether or not that's the actual dream or the thoughts creating the dream is entirely up to the DM.
The level of detail for the deeper probe which reveals:
Deeper probing
There is nothing in the spell description about waking a sleeping target. Keeping it purely in the RAW, the spell works exactly the same on a sleeping target as a conscious one. You can probe deeper, force a WIS save and keep on keeping on. Results of that save will be the same. It is up to the DM if the creature awakens upon the probe or if they continue sleeping only to arise and know as the spell does not specifically say what happens.