Is it bad etiquette to come to office hours that aren't for your particular class? I study mathematics at a large state university. My professors sometimes teach two courses in a given semester, usually two undergraduate or one undergraduate, one graduate course. Typically they hold separate office hours for each course.

I come up with questions about what I'm learning at various times throughout the week, and often it's more convenient to ask this question in the office hours for the other course the professor is teaching, i.e. the course I'm not in. Perhaps it's the fastest way to get my answer, perhaps the office hours for my course have passed for the week, whatever reason.

Would you consider using office hours for a different course (but same professor) bad etiquette? (I do try to give priority to students of the other course, and try to avoid taking up too much time if there are students waiting.)

(Note: most of my professors have a open-door type policy, so I don't think they really mind. This question is more on a general level, i.e. including professors that don't have such policies in place.)
I don't think the professor minds too much, but you should of course be prepared for him to decline if he chooses to. Though I myself could hardly care less, I have colleagues who would definitely think unsuitable (because it's not how it's planned).

However, I think the other students might mind, as you noted, if they began to see it as you “stealing” time from their limited allocation. As always, sharing is no problem unless the resource is scarce :)

So, in short, I don't think it's a big problem, given that you are mindful of others.