Firstly if you're concerned tickets will sell out, then I think that is very unlikely.
However, secondly, you can save money by booking in advance and getting a "promo" fare. These come with restrictions, the cheapest allow no changes or refunds after purchase. If all promo tickets are sold, you will only be able to buy more expensive promo plus or flexible tickets. Although, generally, Spanish rail tickets aren't particularly dear.
On all your routes there are faster, long-distance services (called, for example, AVE or Euromed), that have promo fares. There will also be slower, stopping services - these don't offer promo so it doesn't matter when you buy.
It's worth reading seat61 guide - https://www.seat61.com/Spain-trains.htm