How does nearsightedness know what's near versus far? If I wear a VR headset, I still have to wear my glasses, because the image arriving on the surface of my eye is still arriving as if it were actually far away. But how does that work? Why does the image from a distant object arrive at the surface of the eye differently than a near object?
 A: Let's start by discussing how the eye works.
As you look around, light rays from objects around you are traveling into your eye. They enter through your pupil, are refracted (i.e. bent) by the cornea and lens in your eye, and finally strike the retina, as shown in this image borrowed from here:

The blue lines represent light rays coming in from a faraway object, the object pointed to by the $P_{small}$ label is the lens, and the surface where the light rays converge on the back of the eye is the retina. The photoreceptors - the cells in the eye that sense light and send it to your brain - are all on the retina, so it's important that the image be fully focused there in order for you to see it sharply.
In this image, we assumed that the object was infinitely far away - in this case, the light rays are parallel to each other. But let's see what happens when we consider objects closer to the eye: 

The red dot represents an object, and the blue lines again represent light rays. In both images, the light rays still converge on the retina, so the person can see the object clearly. However, notice that the farther object emits light rays that are more parallel than the closer one. This means the lens needs to bend the light rays less for the farther object than for the closer one in order to get the rays to converge at the same point on the retina. Put another way, Angle A in the image is smaller than Angle B.
How can a single lens manage to focus both nearby and faraway objects, given that it needs to bend light a different amount for each? The lens in a human eye is not actually fixed - it changes shape depending on where you're looking. When you look at something nearby, the lens becomes thicker causing it to bend light more. When you look at something far away, the lens becomes thinner, causing it to bend light less. This is how an eye focuses.
Nearsightedness occurs when the lens is perpetually too strong to bring a faraway object into focus. Even when your lens becomes as thin as it can get, it's still bending light too much to focus the image on the retina:

This means you can't see faraway objects - your lens just can't get thin enough. For nearby objects, though, you have no problem - your lens gets thicker, just as it should, and focuses the object on your retina like in all of the prior images. For more biological detail, see this question.
Cool - but how does any of this relate to your VR headset? That's right up against your face, so why do you still need glasses? VR headsets use lenses to bend the light from the screens to look like it's coming from farther away than it really is. So, when the light rays hit your eyes, they are more parallel like a faraway object's:

Here, the red rectangle is the LCD screen of your headset and the green oval is the lens in your headset. Since the light rays hit your eyes as if they're coming from a faraway object, you still need your glasses to see things in focus.
(Another way to think about this is that the green lens generates a virtual image of the screen far away from you, and that's the image that your eye observes.) 
