For In only the upper class, the only restricts the group (to the upper class as opposed to the lower orders). For Only in the upper class, the only restricts in the inclusion (in, as opposed to out). But no matter which you restrict, there are only two groups under discussion -- upperclass women and and female commoners. So both placements of only end up meaning the same thing. But this isn't always the case. Consider the following two sentences:
I hear the sound only inside my house.
I hear the sound inside only my house.
A reasonable interpretation of the first sentence is the the sound is audible in my house, but I can't hear it once I go into my yard. A reasonable interpretation of the second sentence is that the sound is audible in my house but in nobody else's house. The interpretations are much more certain in speech, if the italicized words are emphasized.