Context. Damped Lyman-α (DLA) absorption-line systems at the redshifts of gamma-ray burst (GRB) afterglows offer a unique way to probe the physical conditions within star-forming galaxies in the early Universe. Aims. Here we built up a large sample of 22 GRBs at redshifts z > 2 observed with VLT/X-shooter in order to determine the abundances of hydrogen, metals, dust, and molecular species. This allows us to study the metallicity and dust depletion effects in the neutral interstellar medium at high redshift and to answer the question of whether (and why) there might be a lack of H2 in GRB-DLAs. Methods. We developed new methods based on the Bayesian inference package, PyMC, to FIT absorption lines and measure the column densities of different metal species as well as atomic and molecular hydrogen. The derived relative abundances are used to FIT dust depletion sequences and determine the dust-to-metals ratio and the host-galaxy intrinsic visual extinction. Additionally, we searched for the absorption signatures of vibrationally-excited H2 and carbon monoxide. Results. We find that there is no lack of H2-bearing GRB-DLAs. We detect absorption lines from molecular hydrogen in 6 out of 22 GRB afterglow spectra, with molecular fractions ranging between f ≃ 5 × 10−5 and f ≃ 0.04, and claim tentative detections in three additional cases. For the remainder of the sample, we measure, depending on S/N, spectral coverage and instrumental resolution, more or less stringent upper limits. The GRB-DLAs in our sample have on average low metallicities, [X/H]¯ ≈ −1.3, comparable to the population of extremely-strong QSO-DLAs (log N(H I) > 21.5). Furthermore, H2-bearing GRB-DLAs are found to be associated with significant dust extinction, AV > 0.1 mag, and dust-to-metals ratios DTM > 0.4, confirming the importance of dust grains for the production of molecules. All these systems exhibit neutral hydrogen column densities log N(H I) > 21.7. The overall fraction of H2 detections in GRB-DLAs is ≥ 27% (41% including tentative detections), which is three to four times larger than in the general QSO-DLA population. For 2 < z < 4, and considering column densities log N(H I) > 21.7, the H2 detection fraction is 60–80% in GRB-DLAs and in extremely strong QSO-DLAs. This is likely due to the fact that both GRB- and QSO-DLAs with high neutral hydrogen column densities are probed by sight-lines with small impact parameters, indicating that the absorbing gas is associated with the inner regions of the absorbing galaxy, where the gas pressure is higher and the conversion of H I to H2 takes place. In the case of GRB hosts, this diffuse molecular gas is located at distances ≳ 500 pc from the GRB and hence is unrelated to the star-forming region where the event occurred.