He said that, not because he thought of it himself. Instead, since he was the high priest that year, he was prophesying that Jesus would die for the whole Jewish nation.