This kind of railroading is unfair, but technically allowed.
The rules on advantage/disadvantage suggest that advantage/disadvantage is applied when the roll is made, not afterward (PHB p.173, highlighting mine):
Sometimes a special ability or spell tells you that you have advantage or disadvantage on an ability check, a saving throw, or an attack roll. When that happens, you roll a second d20 when you make the roll.
The advantage/disadvantage rules in the Dungeon Master's Guide (p.239) say that the DM can impose disadvantage when something makes success less likely, but doesn't say that the DM can use it after the roll has already been made.
The situation as you describe it sounds like railroading, where the DM has an outcome in mind and intentionally prevents the players from changing the outcome to avoid ruining his carefully planned campaign. The Dungeon Master's Guide (p. 71) discourages this:
An adventure should allow the adventurers' actions and decisions to matter. Though it might resemble a novel or TV episode, an adventure needs to allow for more than one outcome. Otherwise, players can feel as if they've been railroaded—set onto a course that has only one destination, now matter how hard they try to change it.
However, the DM can, technically, ignore or change rules, make ad-hoc adjustments to the rules, and make ad-hoc rulings if they wish. The DM has the authority to do so, although with the responsibility to do so in a way that makes the game more fun for the players. As per DMG p.4:
The D&D rules help you and the other players have a good time, but the rules aren't in charge. You're the DM, and you are in charge of the game. That said, your goal isn't to slaughter the adventurers but to create a campaign world that revolves around their actions and decisions, and to keep your players coming back for more!
It may be in this case that the DM has pre-planned a plot, and your skill check, if successful, would break his plot. Many DMs are not confident in their ability to react to such plot twists on the fly, and will sometimes fail to adapt in order to keep the story going. This is technically allowed, but such a DM would benefit from learning to tell a story more flexibly.