Sum rule for the Compton amplitude and implications for the proton–neutron mass difference