Context. The Spitzer Space Telescope has detected a powerful (L(H2)~10^41 erg s-1) mid-infrared H2 emission towards the galaxy-wide collision in the Stephans Quintet (SQ) galaxy group. This discovery was followed by the detection of more distant H2-luminous extragalactic sources, with almost no spectroscopic signatures of star formation. These observations set molecular gas in a new context where one has to describe its role as a cooling agent of energetic phases of galaxy evolution. Aims. The SQ postshock medium is observed to be multiphase, with H2 gas coexisting with a hot (~ 5 10^6 K), X-ray emitting plasma. The surface brightness of H2 lines exceeds that of the X-rays and the 0-0 S(1) H2 linewidth is ~ 900 km s-1, of the same order of the collision velocity. These observations raise three questions we propose to answer: (i) Why H2 is present in the postshock gas ? (ii) How can we account for the H2 excitation ? (iii) Why H2 is a dominant coolant ? Methods. We consider the collision of two flows of multiphase dusty gas. Our model quantifies the gas cooling, dust destruction, H2 formation and excitation in the postshock medium. Results. (i) The shock velocity, the post-shock temperature and the gas cooling timescale depend on the preshock gas density. The collision velocity is the shock velocity in the low density volume filling intercloud gas. This produces a ~ 5 10^6 K, dust-free, X-ray emitting plasma. The shock velocity is smaller in clouds. We show that gas heated to temperatures less than 10^6 K cools, keeps its dust content and becomes H2 within the SQ collision age (~ 5 10^6 years). (ii) Since the bulk kinetic energy of the H2 gas is the dominant energy reservoir, we consider that the H2 emission is powered by the dissipation of kinetic turbulent energy. (Abridged)