A search for decays of and Higgs bosons to and a photon, with the subsequent decay of the to , in proton-proton () collisions at a center-of-mass energy () of 13~\mathrm{TeV}, is presented. The analysis uses a data sample corresponding to an integrated luminosity of 35.9~\mathrm{fb}^{-1} collected with the CMS detector at the LHC in 2016. The observed (expected) upper limit on the decay branching fraction, assuming that the is unpolarized, is at confidence level, which corresponds to 15 (18) times the standard model (SM) prediction. For the extreme polarization scenarios the observed (expected) limit varies from to . The observed (expected) upper limit on the branching fraction for with m_{\mathrm{H}} = 125~\mathrm{GeV} is , 260 (170) times the SM prediction, at confidence level. The from the Higgs decay is assumed to be completely transversely polarized. The results for the Higgs boson decay are combined with the results from collisions at \sqrt{s}=8~\mathrm{TeV} corresponding to 19.7~\mathrm{fb}^{-1} and this results in an expected (observed) upper limit on the branching fraction for of 220 (160) times the SM prediction.