Airplanes are now being equipped with onboard micro-cellular sites and wi-fi equipment, which is then bridged to the ground - or to a satellite - via special data modems. You can find more technical information here, for example.
All equipment inside the airplane can be disabled by the pilot at any time. Legitimate needs include time on the ground, time without passengers, saving power (if flying with less than a full set of generators,) and short or fire.
I flew on a private airplane some years ago from San Jose to San Diego. The captain told us that cell phones stop working pretty fast, but we are welcome to try if we want to. We did try - and indeed they lost signal as we climbed to a few thousand feet, if not earlier. Modern cellular infrastructure is highly optimized, and not much power is wasted.
Ahh, okay. Since this was an older plane for short trips it likely didn’t have the micro-cell sites and Wi-Fi.
Remember the stories about UA-93 passengers using cell phones to call their families? In movie jargon it's called continuity error