This is explained at https://www.gov.uk/capital-gains-tax/rates
There's no cliff-edge where your entire capital gain suddenly changes tax rate because you changed your income tax band. If on the basis of your income, you're a basic rate taxpayer, then you pay 10% CGT on any capital gains between your income and the top of the basic rate tax band. Then you pay 20% on any amount above that.
So for example if you have income of £50,000 and a capital gain of £10,000, you'd normally pay £2,000 in CGT. If you reduce your taxable income to £40,000 either with a normal pension contribution or salary sacrifice, you'll have £5,000 of the basic rate band left. So you'll pay CGT at 10% of £5,000 + 20% of £5,000, i.e. £1,500.
In general, if you have money to spare for a pension contribution, you'd be better off making it over multiple years and only within the higher-rate band. Continuing my example above, and assuming your income is also £50K next year and tax bands don't change, you could either:
- Make the £10K contribution this year, saving £3K tax on the pension contribution (£5K @40% and £5K @20%) and paying £1.5K tax on the capital gain.
- Make a £5K contribution this year and a £5K contribution next year. Total tax saving on the pension contribution is £4K (all @40%) and you pay £2K tax on the capital gain.
The reason for the discrepancy is that income tax goes up by 20% at the threshold, but CGT only goes up by 10%. So if you have to pay the higher rate on something, it's better to do it on the capital gain.