Yes, its a role-playing game. That means that the players "win" or "lose" based on the role they play, not because the DM thinks it would be enhance his idea of the story by the PCs losing now or making them win despite multiple blunders on their side.
You can of course stack an encounter in a way to encourage a certain result. But this is at first just another situation for the players to deal with. If they manage to win an encounter they are supposed to lose they should get that victory despite it throwing off your "awesome dramatic idea". And if they lose an encounter they are supposed to win then it leads to another situation for them to deal with in game. Don't make them win just so that the railroad can continue.
Sure, if they manage to win, good for them. It's so easy to kill a player that you don't have to work hard to do it. I'm telling a story when I DM. I'm not a referee creating perfectly balanced encounters. It's rare it doesn't work out how I plan it including the players suffering a loss because I planned it.
I never understood the DM vs. Player mentality. A DM's job is to make the campaign fun, interesting, and challenging. We all use different methods.
Why can't a DM add specific encounters because he thinks the story is interesting? Players do things because they think it makes their character interesting whether it is a particular appearance, desire to a specific magic item, ability choice, or the like. If I think something is going to enhance my idea of the story, I do it.
Why some people think a DM shouldn't enjoy the campaign he creates, I have no idea. Why do you think people DM? To run a game exactly by the rules so players can feel an amazing rush beating monsters? Hell, no. They run it because they find some aspect of running it pleasurable whether that is encounter or monster design, tactics, role-playing NPCs, or whatever. If I find orchestrating a story a particular way I find interesting, I get to do it. Otherwise, someone else can step up and do the work DMing. If players don't like it, I offer them that option.
You don't get to use the DM for your own purposes. It's a group game. The DM gets to have fun too including doing what he feels enhances the story for no other person than himself. Just like the players get to make all the decisions about their characters capabilities themselves.