The Mg II h and k lines are among the strongest in the near-ultraviolet solar spectrum and their line core originates in the upper chromosphere, just below the transition region. Consequently, they have become one of the main targets for investigating the magnetism of the upper solar atmosphere. The recent Chromospheric Layer Spectropolarimeter (CLASP2) mission obtained unprecedented spectropolarimetric data on these lines in an active region plage, which have already been used to infer the longitudinal component of the magnetic field by applying the weak-field approximation. In this paper, we aim at improving our understanding of the diagnostic capabilities of these lines by studying the emergent Stokes profiles resulting from radiative transfer calculations in a radiative magnetohydrodynamic time-dependent model representative of a solar plage. To this end, we create a synthetic observation with temporal and spatial resolutions similar to those of CLASP2. We find strong asymmetries in the synthetic profiles of circular polarization, which considerably complicate the application of the weak-field approximation. We demonstrate that the selective application of the weak-field approximation to fit different spectral regions in the profile allows us to retrieve information about the longitudinal component of the magnetic field in different regions of the model atmosphere, even when the circular polarization profiles are not antisymmetric and are formed in the presence of strong velocity and magnetic field gradients.