The complex chemistry of hot cores in Sagittarius B2(N): Influence of cosmic-ray ionization and thermal history