You're quite likely to be sleep-deprived and jetlagged when you arrive on June 23. It's an extremely bad idea to go to Bordeaux, rent a car, and spend probably at least 4 hours driving to Sarlat (plus time spent stopping for lunch). Are you sure you'll be safe to drive?? I would definitely not be. Then you'll arrive in Sarlat in the late afternoon, wanting nothing so much as to go to sleep. You probably won't have the time, the energy or the initiative to do much that day. So you'll really have basically one day (June 24) to see a tiny bit of the Dordogne, and you will have subjected yourselves to two utterly exhausting travel days to pull that off. The Dordogne is a wonderful area, but it's not a good place to spend one day if you have to kill yourselves to pull it off.
The next day (June 25), you have to allow time to drive back to Bordeaux (4+ hours) and return the car (possibly not exactly instantaneous) before getting on the train heading to the border. There are Bordeaux-Hendaye trains departing at 7:42 AM, 10:02 AM, 12:02 PM (arrives 2:31 PM), 12:50 PM (arrives 3:21 PM), 2:50 PM, and 3:02 PM. What time will you need to step into the car in Sarlat to be reasonably sure of making the 12:02 PM train--6:30 AM? You may still be jetlagged on the morning of Day 2. I would be miserable and not necessarily safe to drive.
So let's say you do make that 12:02 PM train out of Bordeaux and arrive in Hendaye at 2:31 PM. If there were a 2:30 PM San-Sebastian-Madrid train on the Thursday schedule, you'd miss it, but I don't see one. It looks as if your departure-time choices from San Sebastian will be 7:28 AM, 8:57 AM, 11:14 AM, 2:04 PM, 4:10 PM and 4:33 PM.
It's about 16 miles from Hendaye to the San Sebastian train station; I don't know what the drive is like or how long it's likely to take--or whether it will be difficult to get a taxi in Hendaye that can/will take you to San Sebastian. But the best you can hope for is the 4:10 PM train, which will get you to Madrid at 10 PM, at which point you will have been on the move for 15+ hours. (The good news is that shooting for the 4:10 out of San Sebastian means you might feel comfortable taking the 12:50 PM departure from Bordeaux and sleeping a few minutes longer. I wouldn't, because stuff happens.)
Trains do not always run on time. That's probably a bigger risk with TERs (the 12:50 PM departure from Bordeaux) than TGVs (the 12:02 PM departure). Since the Bordeaux-Hendaye train is French, you have that annoying Hendaye-San Sebastian transfer to deal with, and the San Sebastian-Madrid train is Spanish, I'm not sure there is any way you can buy your train tickets and be protected so that the second ticket can be adjusted if the first train makes you late. I fear that if something goes wrong, you'll have to buy a new ticket from San Sebastian to Madrid. The full fare on the 2:10 train seems to be 72 euros.
One other thing: I believe French rental-car agencies often close for lunch. Be sure the ones you plan to use for pick up and drop off will be open when you need them.