Arriving Madrid at 8:00 am going to Leon. Train from Chamatin 1st at 11:05 am 2nd at 2:40 pm.. Think the 1st option might be tight, with customs getting to the station etc.. Purchase tickets prior to arriving in Spain or do it at the train station at the airport?
The usual recommendation is to wait until you're in the airport to buy onward tickets. Just too big a risk of delays. However, if you're looking at tickets 60 days or more ahead of time, are seeing give-away prices and want to roll the dice, it wouldn't be a crazy thing to do. Just compare the price you will pay to the price for tomorrow's trains to be sure you're potentially saving enough to make the risk worthwhile, because you may be throwing away that ticket and buying a replacement.
Atocha Station is sort of large, and some of us find it confusing. The Cercanias trains coming in from the airport and other nearby areas use a different part of the station from the platforms used by the AVE and ALVIA trains to Leon, so you'll need more than the usual 5 minutes to make the connection. And the fast trains sometimes (always?) require that your luggage be scanned before you get down to the platform.
Edited to add: Philip is correct: The train from the airport will take you to Chamartin as well as to Atocha, so you can avoid dealing with changing trains at Atocha, plus it saves time.
Trains leave the airport for Chamartin every half hour and take only 15 minutes for the trip. Timing can depend on whether you have to wait for checked luggage. I personally think, if you are just using carry ons, that you could easily make the earlier train. But I'm the eternal optimist.
Remember to check what terminal you arrive at. The airport train departs from Terminal 4. Madrid-Leon full (flexible) fare is about €50 in Turista and €65 in Preferente.