When an apple is cut open, an enzyme called polyphenol oxidase is released from the cells of the apple and reacts with the oxygen in the air - this is what causes the fruit to turn brown, a reaction similar to rust forming on a metal.
Lemon juice is able to prevent this reaction from taking place because it contains ascorbic acid (Vitamin C) and because it has an acidic pH. What happens is, the ascorbic acid will now react first with the oxygen, preventing the polyphenol oxidase from doing so; however, after the ascorbi acid is used up, polyphenol oxidase will react with oxygen and the apple will start going brown.
Lemon juice's acidic pH also has an impact on the reaction between the enzyme and oxygen, since polyphenol oxidase works best at
Besides lemon juice, lime juice and cranberry juice also work well because they have pHs below 3.0.
Here's a nice video on this process