Sometimes, as a DM, you need to put your foot down and say, "Okay, I know that you, as players want to do this, but why do your
characters want to do this? What brought them to this decision?" If they manage to come up with a good excuse and it sounds like a legitimate plan, there's a few things you can do.
1) Pretend to go along with it and throw a "random" encounter their way that you prepared for just a situation. This is your panic button, and should be used sparingly. The encounter should have some relevance to the scene, but be strange enough to warrant further examination by the party. It's essentially a side quest to divert them from something you're not prepared for.
Keep in mind that if they ask you if you're steering them from their unexpected adventure, it's best to tell them that you are, but you'll have prepared for their quest next time so it won't suck as much as it would have if you'd done it that day.
2) If you feel confident enough to do it and have the resources to do so (Such as a map, some random "important" NPCs you can throw in for flavor, and generic NPCs), go for it. If it makes sense, try to twist it back on them and help them realize the extent of their bad idea (If it truly is bad). I'm not saying throw in an invincible NPC guard at the prison: That's a little too heavy handed. Depending on the setting, you might have the majority of the prisoners be legitimate scum, with a few really bad apples claiming to be innocents that have been wrongfully imprisoned. Naturally the players will joyfully bite, freeing a number of serial killers, rapists, and career criminals into the world.
This will initially only surface in the form of town criers spreading news about the prison break lead by an evil gang to wreak havoc on the innocent masses, but if that doesn't work, have it bite them in their rear in the worst possible way. Someone discovers that it was the players who released the prisoners, turning the general populace against them but making them a magnet for the worst of the worst... Who just want to join the players' "gang". Now the players have to deal with a band of murderers and rapists following them around, performing evil in their name.
Such an action would also be considered, in the least, chaotic, and depending on the players' intentions, evil. Any character who repeatedly participates in that kind of stuff runs the risk of losing powers linked to their classes, or at least an unpleasant surprise for the afterlife.
Naturally, only go for this if you're sure you can pull it off without pissing the actual players off. Only take it as far as your confidence, skill, and preparation can get you. This should only be taken to the extent that it makes sense, too. Punishing your players because they had a legitimately good idea to defeat the Big Bad or bypass one of your puzzles is a very bad idea.
3) This kind of goes along with #2: Prepare a bunch of generic crap you can throw into any situation. This is strictly on a "as you think of it or feel like it" basis, do not overwork yourself.
Think of things that the players might run into in your setting. Bandits? Guards? Orcs? Monsters? Inquisitors? Have a few meat grinder NPCs that you can toss at the players if they diverge from where you thought they would go, and, if you're feeling particularly adventurous, you can make level appropriate encounters, too. Don't go too overboard, but remember this is a good fallback if the players just want to kill some dudes.
As I mentioned earlier, have a few generic NPCs you can use in a pinch. They should consist of names, basic combat abilities, and a broad overview of their equipment. Having two "quirks" would be great, too. They are, essentially, a meat grinder NPC with a little bit more flavor attached to them. Need to flesh out a shopkeeper? Choose a random dude from your list of NPCs, and role play him based on his quirks. Your players are more likely to remember Smith the stuttering, sneering prison guard than Luke, the guy you took five seconds to think of a name for. More powerful characters can also make great on-the-spot bad guys or even folks who help the PCs when they're in trouble.
Ideally, you should have this list within arms reach so it seems like you prepared for introducing a character all along, and the list should have room for notes so you don't accidentally reuse NPCs and so there's some consistency if the players run into the same NPC in the future. Don't beat yourself up about it, though: Just do a couple NPCs whenever you have some spare time. They're not super important, since they're just flavoring, but they can bring a random campaign to life.
4) Finally: Be honest with them out of character. Tell them, "Sorry, I'm not prepared for that. Could we do X, instead, and I can prepare for that side quest next week?" Don't do anything you're not comfortable with. If the players are insistent, it's time to start thinking about whether or not they're good players or not. Sometimes people do things just to be douche bags, even without noticing it - But that's a whole different advice column.
Used sparingly and with a good reason, "No" can be very powerful. Just be sure to explain
why, and have an open mind about whatever answer they give.
Just remember that these guys are your friends, and you're hanging out to have fun. If they're not being very friendly and you're not having fun, it's time for some introspection.
Fear the Boot has a variety of podcasts and forums that are invaluable resources. If you have time, browse through the podcasts for the topics that cover first-time DM'ing, or at least check out the forums. There's usually a "New DM" topic going at any given time, and if there isn't a quick search will get you what you're looking for.