Baggage is a little slow in MAD, so give yourself a little time. The passport control was not bad,but I think there were no other international flights at the time I got there. I had to wait for the ticketing for the Cercanias to open (10:00, as I recall), as my code for the free ticket (it’s free when you buy your ticket to León) was not read by the ticket machine.
The trains to Chamartin run frequently ~every half hour, and it’s an 11 minute ride. You can then get on a fast train to León, and be there in a couple of hours. The one I’m thinking of left at about 2:30 or so. There are also the regular, slower local trains. I was in León by supper time (for me), which was a little difficult, since most eating establishments are closed until 1900 or 2000, 7 or 8 pm. If you’re jet lagged it may be hard to wait up for dinner.
Buy your ticket for León online at the Renfe site (It’s simple, and there is an English option, if you need it) as soon as you can. You’ll get a good price that way, and a seat.
I’ve done this three or four times, and it works well for me.
Good luck, and buen Camino.
Paul