Students learn they can ask silly questions by the way the teacher models appropriate responses. If one resists the urge to say, "Really?" in condescending voice, then students will never know it was a stupid question and the issue will never arise. If other students are inclined to giggle, cut that short by saying, "I'm glad you asked me that because that is such a common point of confusion I have to remember to go over that at least a couple of times each term." And so on.
If one feels the need to announce that this particular class is intended as a safe environment, than something along the lines of "There are stupid questions, but that's okay, you are likely not the only one wondering about that topic/issue, so please have the courage to be the one to put that into words." Reframming from 'stupid' to 'courage' goes a long way to creating that positive classroom environment.
Further, even the stupidest question may not be stupid at all—it just came out wrong. Making fun of that slip of the tongue is NEVER a good idea. Even if you think the kid is 100% okay with such banter, chances are s/he isn't. One of my student teachers shared with the class how in grade 7 he was trying to ask about how long the war of 1812 lasted, but it came out "When was the War of 1812?" The teacher made a joke of it, and my student laughed right along with everyone else because, although thoroughly embarrassed, one has to be seen to be able to laugh at oneself, right? But the teacher didn't let go of it and would ask, "When was the treaty of 1615 Zac?" and so on every opportunity. Worse, other teachers in the school took it up, until it became a daily humiliation for the student. But he never said anything or allowed any of his teachers to suspect how he was responding to their jibes because he wanted to appear 'cool'. But he was not cool with it. It made that term hell for the student, and his grades nosedived. He stopped wanting to go to school. And his voice still quavered recalling that term a decade later when recounting it to my class.
It always amazes me how much rhetoric there is about taking a stand against bullying in the schools, when in fact it is the teachers who are often the worst bullies. Just saying.
Which brings us to the issue, what do we do with the student who asks deliberately stupid questions? You know the kid I mean, the wisenheimer in the back row who has figured out how to disrupt class by asking time-wasting obvious questions.
Step one: stop thinking of that kid as a wisenheimer. Again, you can't assume that the kid in the back isn't seriously asking, even if he is projecting a strong image of "I'm only asking this to be disruptive, because of course everyone knows that answer already, right?" Not so much. To be cool, kids have to pretend in front of their peers they know everything, and posing as a wisenheimer is a very effective strategy for them to be allowed to ask questions to which they really, really need the answer.
Step two: real or not, treat every question with the same dignity and give as serious a reply as you would to an honour or transfer student who really needs to know. If the student really wanted to know, they will be grateful; if they were being a jerk, well, treating their answer as serious defeats the purpose of derailing the class. "I'm glad you asked that Roldand! Because that's the key to it all!" (Or "that's more complicated than one might think!" or "I can't emphasize / go over this enough times" or etc) Suddenly they have been cast in the role of legitimate helpful student. There may be a brief period of confusion where they try to figure out whether you are really that gullible or whether you are playing them but either way, extinguishes the (apparently) negative attitudes and the next thing you know, they are fully participating in a class where someone is suddenly taking their input seriously--whether they started out that way or not.
Finally, there is the not-as-silly-as-you-assumed question. If a student asks a stupid question, respectfully poke around a bit by asking why they are asking to ensure you understood the actual question. It may not be a silly question at all, but merely that you did not understand the context or significance of why they were asking. Think of Giant Pandas next time you get a stupid question in class....