Because they are pressurised, and they are controlled very carefully.
Most people get hypoxic (not enough oxygen) above about 10,000’ depending on the individual. If your aeroplane cabin depressurised at 20,000’ then you’d probably be conscious for about 10mins, once again, depending on the individual. Commercial passenger jets generally fly between 30,000’ - 40,000’, at 30,000’ you’d have more like 2mins of consciousness if that. Ideally, the cabin would be pressurised so that at 30,000’ the cabin was still at the same altitude as the departure airfield. This isn’t practical though for structural reasons.
As a compromise, the cabin is pressurised so that the cabin altitude is low enough so that people stay awake and lucid, but not so low that the walls need to be super strong.
The result is that the cabin is generally pressurised to around 8,000’. When the aircraft goes up, the cabin goes up as well, but at a slower rate. When the aircraft comes down, the cabin comes back down, also at a slower rate. This means that you can still suffer from pressure related problems such as stomach upsets, toothaches, burst eardrums, and the “bends” if you’ve been SCUBA diving recently.