Sometimes PCs take the wrong approach with an NPC. Sometimes the approach is so bad it is hard to conceive of a way for the NPC to do anything but give a hard no and shut off an avenue of inquiry. Doing so doesn't even violate the normal advice for GM's to not say no, because this isn't the GM saying no but the NPC. Still, it is something I find that you want to be really careful with - and if possible find a way to warn the players before it happens.
The Danger of the Hard No
The danger with a hard no, even from an NPC, is that it can leave the players feeling like they have no direction to go in. This can be the furthest from the truth. You could establish multiple options for people to use, and this is just shutting off one of those paths. In the moment however, the players won't feel that way. They'll feel like the path they tried was rejected. This, in turn, can make them feel like there is only one right way - and that you will only let them do a thing one way.
To say the least, this is not a constructive attitude and can bring a game session to a screeching halt. Even then, and even with time to cool off, I've rarely seen players fully acknowledge that the problem was in how they approached the NPC as opposed to approaching the NPC at all. Even when the 'approach' was taking hostages and making threats to an NPC who had no reason or positive gains from what the PCs wanted, nor any value to the things being threatened or taken hostage.
If Possible, Warn Before
You should know your PCs. And you should definitely know your NPCs. If you see the two heading for a clash - where perhaps there ought not be one for what the PCs are trying to do - it can be beneficial to warn the PCs ahead of time about the possibility. A simple "Your characters would know that this NPC won't react well to X/Y/Z approach, so it might be better to try A/B/C." Or an even less specific "How you approach the social situation will determine as much as your rolls whether or not you can gain anything. Just be aware before hand."
These warnings are good to give early in a campaign when social situations first come up. They are also good to remind people of if you haven't had social situations for a long period of time.
This is good because it lets the players know ahead of time that 1) this avenue is open for them to explore if they want, but 2) how they play it is more important (or as important) as their dice rolls. Having that established ahead of time makes when that hard no is earned feel a lot less like a capricious GM and more like the in character consequences of their actions.
Warn During the Scene
If you see the scene going south fast, and PCs responding to soft nos by doubling down on the path that is hurting them, it can be beneficial to give the most socially aware character an aside that their current plan is not only not working, but liable to shut down the possibility of any gain going forward. This lets the player know before things get locked out that that can happen. It is less good than warning before the encounter, but still a warning that something about what they're doing is down a path less than optimal for their intended goals.
This works particularly well as reinforcement if you did warn before the scene. It can also be done softer and earlier. "The king is taken aback by your approach and hardens his resolve before saying..." can be a big clue that the path taken is not the right way to get a 'social' win with this character - at least not with what the PCs have shown they have in paly.