This is a good example, because it is entirely within the DM authority to pull this move, but is not "good" DMing, in that it feels forced and does not lead to interesting or creative gameplay. Per the core loop of 5e, the DM described the situation, the players narrated their solutions to the situation, and the DM narrated the result, all a few times over. The players expect that their choices would be meaningful within the context of the situation, but the fact that it resulted in a fight made them seem not meaningful. You don't trust that the DM is not using their authority over the fiction ("DM narrates...") to force their encounter on to you no matter how you try to avoid it.
As an introduction, I'll point out that I'm not responding directly to you below, it's just that your post touches exactly the core of the problem for me, so don't take anything below as a reference to you specifically, actually I think I'm pretty much in line with you.
And here you come to the core problem, the lack of trust. And for me, once more, and as I've pointed out
right at the beginning of this thread, the problem here is not even the railroading or the lack of if, it's just the fact that the player does not trust the DM to do the best he can for his players to have fun.
Because this is where the first breach of the social contract probably occurred, you know ? Lacking the trust that the DM will do his best...
I will insist on "the best he can" first, because it's almost a side note in all this, but it's easy for you guys to say, after the fact, but the "DM should have done this". I sure you are all fantastic DMs, and you never make mistakes (actually, one of
@pemerton's redeeming features is that he actually admitted committing a mistake once, although as it was to show, just after, how nice he had been in correcting it and accepting the player's remark, it sort of diminishes the value the example, but still

), but DMs are human beings, you know, and those of us who actually DM (and not only hide behind the internet to spout theories, I'm not saying this for you
@Malmuria) make mistakes sometimes, despite our best intentions, the brilliant solution does not appear to us during the game but only after... If there is no forgiveness and discussion, but just slamming doors, well, I find it really sad and inhuman in what is designed to be the most collaborative and friendly game of all.
But coming back to the trust, I find this example extremely symptomatic. Maybe the DM did a dubious move here, the scenario called for a fight, he needed time to see where the plot was going because he had not prepared enough, and what the players did surprised him, maybe he is not the best at improvising and he knows it, etc. Maybe it WAS forced, and not a shining example of DMing.
But also maybe, just maybe, the Duke is really swamping the areas with his men, maybe he has the best tracking dogs in the region, maybe he has flying/sneaky scouts (that were not seen because they rolled well on stealth, and beat the PC's passive perception, at disadvantage because they were hurrying), maybe he or his advisors are geniuses and deduced where the players might be going next, maybe he has an incredible intelligence network, maybe he tortured one of the PCs friends in town, maybe he used magic (this is D&D, by the way, there are tons of magic, everything the DM can imagine, it does not have to be codified in the PH and approved by the players beforehand), there are millions of ways this can be explained from the DM's perspectives and things that the PCs should not know about, have absolutely no reason to know about, and where not clever enough to investigate about or deduce...
In which case, the lack of trust just destroyed the situation and the game.
You know what a really, really good player would have done ? He would not have stayed in his character as previously defined, he would not have felt "forced", he would have rebounded on the situation, still in character: "Gods, they found us ? How did they do that ? Did we miss something ? Does the Duke now have access to resources allowing him to track us despite our best efforts ? If so, our hideout is in danger, what about our comrades there, we must hurry ! But maybe it's dangerous, the Duke might track us there, maybe we need to find a messenger or another way to contact our friends ? And, gods, what about out host, what did they do to them ? I hope they did not come to any lasting harm ! But if they have, by all the gods, I shall avenge them upon the body of the Duke, in the meantime, let's' deal with this curs and send them yapping back to their master !"
That way, there is no trust lost (and for the DM's it a huge relief too, he knows he can trust you to move along towards a better adventure), you are fully in the game, you have seeded lots of things (as a DM I love it when players do things like this, because I can rebound on some of them, but obviously not necessarily all, and I'm lucky to have players do this very often - or is it luck ?

) that will enrich the game, you have really co-created a collaborative game and kept the ambiance rolling forward at a good pace.
Which does not prevent the really, really good player to go and see the DM at the end of the evening and ask him: "Are you OK, did we surprise you with the Folk Hero thing, it seemed a bit awkward and a good idea at the time but maybe it threw a span in your works ? How do we deal with this in the future ? Are you happy with the way you are running the campaign ? Are you happy with the way we play ?
Do you need some help ?"
Because this is what a really really good player does. He is not an entitled little j...k only preoccupied with his sacrosanct "player agency", with his holy interpretation of his "role", with his demands to be entertained or engaged. He is not a guy that absolutely wants to twist the game HIS way, with HIS expectations overruling anyone else's expectations or work. He is a guy that really helps the game instead of being stuck up with his nasty attitude and theoretical principles that simply make people j..ks.
Contributing to the story in a collaborative mode is not forcing one's own stories and views down anyone's throat, and calling a DM a bad DM if he dares do the same to you. It actually starts with helping all the others have fun first and foremost, even when playing your character, and roleplaying him. And it starts with trusting the DM and the other players, trusting that they are here in the same spirit.
So try it sometimes, instead of roaring in flame when you think your DM is infringing on your sacrosanct player agency, try trusting him. Try to roll with it in the right spirit. And then come and tell us about your experience. Honestly, it has totally changed the way I play and DM since I realised that and stopped being an entitled little j...k as above.
Anyway, so did the player discuss it with the DM at the end of the game ? Did he know why the DM played it that way ? Did the lack of trust continue to exist, to again poison the relationship and the future games ? Or did the DM and the player discuss it openly, understand each other, forgive each other and hopefully reinforce their friendship and make for much better games in the future ? That is all that matters to me.