Whether or not it's a good idea to tell your players out-of-character to fetch other opinions first depends on your group. However, there are other means to achieve what you want.
In general, if my DM told me out-of-character to rethink a course of action that I planned ingame, I would feel a little tricked, "spoilered" and yes, also a little like the DM is taking away my player agency. Unless the DM forces me to do something, it's more of the former rather than the latter, though.
In the end, it depends on your group / your players whether or not they will appreciate or dislike you telling them something like this OOC.
That being said, I recommend that you avoid telling your players anything out-of-character that is relevant ingame. However, if your players do always listen to the advice of the first guy they ask about something, there are a number of ways you can tell or teach them in-character.
We have two kinds of situations here:
- the guy giving them advice is, in reality, a bad guy, and they should not listen to him.
- the guy giving them advice is really a good guy, and it's ultimately a good idea to listen to him.
The first situation is significantly easier to resolve. Show them that the given advice is untrustworthy, either by disproving it or by discrediting the bad guy who advised them.
For example, if a supposedly trustworthy, but in reality bad guy told them to go kill person X, you can, on one hand, show X while doing heroic feats, such as defending a village against an Orc attack or playing happily with the village's kids (in a non-pedophile way, obviously).
On the other hand, you can also let the players notice the advisor in shady places or interacting with shady people, maybe even performing evil / morally wrong acts.
Either way, showing the players how other people interact with the guy in question can give them an indication as to whether they should trust him or not.
The second situation is a little trickier, although it is related to the former. More specifically, your players seem to be a little naive when it comes to trusting strangers, so if you present them with a situation such as (1) on purpose, they might starting acting more cautiously.
If that's not how you want to teach them, you can instead present them with an NPC that has a different opinion. For example, maybe he overheard them talking to the guy giving them advice, and he disagrees and recommends that you do Z instead.
In addition, this might be the point where you can - and maybe should - indeed talk to your players out-of-character. More specifically, it appears that they expect to be railroaded (i.e. basically everything you present them with is set up in a way so that the most obvious choice is the one you expect them to take, such that your plot works out).
Clearly, that's not what you have in mind, so you should engage in a (retrospective) "Session Zero" where you work through, for example, the Same Page Tool.
In summary, you could do one of the following:
- actively present them with alternatives
- show them the consequences of not seeking out potential alternatives on their own
- align your expectations, as is usually done in a session 0.