Determining the black hole masses in active galactic nuclei (AGN) is of crucial importance to constrain the basic characteristics of their central engines and shed light on their growth and co-evolution with their host galaxies. While the black hole mass (MBH) can be robustly measured with dynamical methods in bright type 1 AGN, where the variable primary emission and the broad line region (BLR) are directly observed, a direct measurement is considerably more challenging if not impossible for the vast majority of heavily obscured type 2 AGN. In this work, we tested the validity of an X-ray-based scaling method to constrain the MBH in heavily absorbed AGN. To this end, we utilized a sample of type 2 AGN with good-quality hard X-ray data obtained by the nuSTAR satellite and with MBH dynamically constrained from megamaser measurements. Our results indicate that, when the X-ray broadband spectra are fitted with physically motivated self-consistent models that properly account for absorption, scattering, and emission line contributions from the putative torus and constrain the primary X-ray emission, then the X-ray scaling method yields MBH values that are consistent with those determined from megamaser measurements within their respective uncertainties. With this method we can therefore systematically determine the MBH in any type 2 AGN, provided that they possess good-quality X-ray data and accrete at a moderate to high rate.