I think there is some logic to swapping out both, but it will depend on your vehicle history.
If you replace the slave, the mere act of bleeding the system can push the master beyond its normal operating stroke, perhaps picking up a bit of rubbish, and nicking the seal. New master time.
Also, if one is leaking, there is opportunity for moisture to get in and corrode bits, making the above more likely.
Also, clean brake fluid is very good at cleaning stuff, removing any sludge that may be in there helping a seal, seal. By washing it away it can cause an earlier failure than would otherwise have been.
So if you know your vehicle history, then go for it, just replace the slave. On my Audi, the slave went recently, at only four years old, I had to replace the master shortly after (the original 28 year and 200,000 miles old), so I know that is still good, and it is not showing any leaks. So, I shall just replace the slave. I was getting some other odd symptoms, so I am also replacing the pipe/hose from master to slave (£100 from Audi) to make sure I don't have any further problems.
If you open the cap on your master and it is full of black sludgy stuff some might call brake fluid, then it may well just be a good idea to do the lot.