Well, you can learn something from almost any encounter, and as previous posts have pointed out, sometimes it is about you and sometimes it is about them.
I would make the distinction between "feeling stupid" in the sense of seeing that your question collapses or doesn't really strike at the heart of things, and "feeling stupid" in the sense of feeling that you have no place in the discussion/no future in the field.
Avoiding the second is mainly psychological (as well as knowing when to filter out unnecessary criticism from authority figures). It's an important and worthy topic, but so is the first, which is what my personal strategy would be to focus on. There is a great art to asking good questions.
It can be hard to recover emotionally as a lecturer from being asked an off topic question and for this reason many people get frustrated when confronted with "bad" questions -- let me explain this. After all, a teacher has been pouring out their intellectual soul to you for a quarter, a semester, or even just the hour so far. You're sitting there listening -- they assume you understand. When you open your mouth, they get to see whether or not that was true.
If you've ever watched a bad talk show host, you can see what an effect this has.
Every field has its own language of relevant questions. If you spend a lot of money on a nice bottle of wine and open it for your new neighbors, and the guy swirls it in his glass and says "Wow, exactly the color of cherry Pepsi," you know in your heart that he's not going to appreciate it the way that someone who says "Malbec?" would. Maybe the Pepsi remark is not so unreasonable, but it doesn't matter. It is incumbent upon the person who wants to be educated, to be initiated into a field, to explore the field's strange vocabulary and to figure out what questions it considers interesting. How do people speak about the subject you care about? What do they ask, and why? What are the key details -- what does one pay attention to?
Practice on yourself -- on your friends in the course -- on your TAs. Start debates at your dinner table. Post questions online (if such a course were to arise again, I'd be willing to bet a number of people here know about the church fathers). Make friends with the "smart kids" in the class and see how they think about things. And then start asking, slowly. After a couple of months of effort, usually there is either a breakthrough where the new language starts to seem much more interesting/relevant, or else you may decide this particular field's way of categorizing knowledge is not your cup of tea, which is also worth knowing.
In general, any serious insight into how people organize the world will turn out to be very useful information. Understanding "what is a good question?" in any given domain is one of the best ways to achieve this kind of insight.