Two-loop radiative jet function for exclusive B-meson and Higgs decays