We study a class of Hamilton-Jacobi partial differential equations in the space of probability measures. In the first part of this paper, we prove comparison principles (implying uniqueness) for this class. In the second part, we establish the existence of a solution and give a representation using a family of partial differential equations with control. A large part of our analysis exploits special structures of the Hamiltonian, which might look mysterious at first sight. However, we show that this Hamiltonian structure arises naturally as limit of Hamiltonians of microscopical models. Indeed, in the third part of this paper, we informally derive the Hamiltonian studied before, in a context of fluctuation theory on the hydrodynamic scale. The analysis is carried out for a specific model of stochastic interacting particles in gas kinetics, namely a version of the Carleman model. We use a two-scale averaging method on Hamiltonians defined in the space of probability measures to derive the limiting Hamiltonian.