Cordoba is considerably closer to Seville than to Granada, so it would be better to do a Cordoba day trip from Seville (adjusting the number of nights there) than from Granada. The fast trains from Seville take less than an hour. The slower Media Distancia trains take only about 1-1/2 hours and would save you a lot of money (fare is fixed at 11.20 euros one way); you'd need to decide whether the financial savings are worth the loss of time in Cordoba, a city with a lot of sights. Perhaps take one of the faster trains to Cordoba and one of the slower ones on the way back?
A significant extra advantage of doing the side trip from Seville rather than Granada is that there are more trains between Cordoba and Seville. Service between Cordoba and Granada is somewhat more sporadic, with some big gaps in the schedule that might affect your flexibility.
Another possibility: Where are you going to be before and after your stay in Granada? Most (maybe all) trains between Madrid and Granada go through Cordoba. Most trains between Seville and Granada go through Cordoba. In some cases you'd be changing trains in Cordoba anyway. You might be able to visit Cordoba in transit--ideally spending one night there. Even if you can't spend a night in Cordoba, you'd at least save on train time, and probably on train fares.
Be aware that unlike most other countries in Europe, the express trains in Spain quite often do sell out. You'd always be able to get on a Media Distancia train from Seville, though finding a place to sit wouldn't be guaranteed. For the trip from Granada to Cordoba, you could run into multiple sold-out trains on your preferred day of travel if you didn't buy the tickets in advance. Keep in mind, though, that the cheapest tickets will not be refundable or changeable without at least a signficant fee.