Local adaptation and the evolution of inversions on sex chromosomes and autosomes