lordabdul
Explorer
Replace "achieve goal" to "resolve goal": the goal can be achieved or failed, but it gets resolved in a dramatically satisfying and fun way. Ending up lost in the woods and giving up, going back to town to find another mission, is not a very good resolution IMHO. Finding the Necromancer's hidden castle in the woods but getting your ass kicked andInherent in your questions, I believe, is a presupposition that the characters' goal needs to be achieved. It doesn't. As the PHB or Basic Rules points out, the characters can totally fail and the players can still "win" provided everyone had fun and created an exciting, memorable story by playing.
As for the door problem, regardless of the sandbox/plot-based/whatever, it's not uncommon for players to grab onto some detail that the GM thought was totally inconsequential. In that case the GM should make sure this door is indeed uninteresting (for example the door can be opened and leads to a broom closet), because most of the time, if you make the door locked and hard to open, that will only strengthen the players' belief that this door will lead to something awesome. If that happens, you can stall things by saying the door emits some weird magic and so the players need to go on a side-quest to find the item or NPC that can open this door, and this way you get a week or two to rework the castle's map or whatever until the next session... or maybe the players will try and find another way into the castle because they're in a hurry (possibly because you improvise a time limit on the spot... "as you study the door, you hear the sound of an army gathering inside the castle, ready to head out on a raid").
Either way, there's no badwrongfun. The GM should do whatever she can to make things fun. If the players' immersion and suspension of disbelief are still good, and if things were more fun than the GM just saying "no you find nothing/no you can't get in/etc.", then it's the GM did the right thing. If the players feel railroaded or misled or whatever, then with constructive feedback the GM will learn and do better next time.