I'd do it 2 or 3 weeks before if you can. It's only a 5k so it won't leave you too tired to race the next week or anything, but I'd prefer doing it 2 or 3 weeks out for 2 reasons:
1: A 5k race is a pretty good workout. I think it would be better to reap of the benefits of this workout before the race you're peaking for (~2 weeks or so).
2: If it's only a week before, you might get used to your 5k pace and start your 10k too fast. Instead do something like 3-4 miles at your 10k pace (or some 1k-3k repeats if you want). You're not going to gain any fitness a week before your race, but you can practice running your race pace (both from a mental standpoint and from a muscle-memory standpoint. Also, if you do a 5k time trial a week or 2 before this workout, it will give you a pretty good idea of how fast to run it.