Rick warns that trains heading back to Madrid can sell out; I think he recommends buying the return ticket at the same time you buy the ticket to Toledo. I would point out that I've even see sold-out trains headed to Toledo. There are no guarantees you'll be safe waiting to buy either ticket, especially around a holiday. In a pinch, there are also buses between Madrid and Toledo, but they take a great deal longer than the trains, and I cannot guarantee they won't be full.
I'm hyper-cautious about giving advice on this issue because I once ran into a sold out-bus from Bilbao to a fairly obscure city (not San Sebastian) and had to wait 2-1/2 or 3 hours for the next departure. That was back in 2016.