Probably thats the case. What x.bam refers to in your example? Here is what I did: Retained only reads aligned to chromosomes 1:22:
samtools view -o out.bam in.bam seq 1 22 | sed 's/^/chr/'
Took the header:
samtools view -H out.bam > header.sam
The header.sam still has the '@'SQ line for all the removed contigs. So, manually copy pasted the '@'SQ lines related to chr 1:22 and '@'PQ lines (newheader.sam) and used it for samtools reheader:
samtools reheader newheader.sam outbam.bam > newbam.bam
Based on your response, the manual modification of header file could be reason. In your example, how x.bam doesnt include the headers from the removed contigs?