All long distance express trains on that route (Madrid - Barcelona - Perpignan - Montpellier - Marseille - Nice) will require a seat reservation. If you book these trains in advance you will get cheaper tickets, however you will have to travel with the booked train. If you prefer to have more flexibility you can of course buy tickets (including reservation) locally at train stations but will pay the more expensive standard fares.
Depending on how many stops you want to make and how long you want to travel you could also look at a 5in15 Interrail pass: rail.cc/en/interrail-global-pass-5-in-15-days
From Madrid to Barcelona there are frequent (1-2 trains per hour) AVE high speed trains: rail.cc/en/train-type/ave-renfe/23
There is only one regional train each day, taking 7 to 8 hours for the trip.
Barcelona to Nice: blog.rail.cc/barcelona-marseille-nice-train/