Leading neutron energy and pT distributions in deep inelastic scattering and photoproduction at HERA