Our study introduces a new machine learning algorithm for estimating 3D cumulative radial profiles of total and gas mass in galaxy clusters from thermal Sunyaev-Zel’dovich (SZ) effect maps. We generate mock images from 2522 simulated clusters, employing an autoencoder and random forest in our approach. Notably, our model makes no prior assumptions about hydrostatic equilibrium. Our results indicate that the model successfully reconstructs unbiased total and gas mass profiles, with a scatter of approximately 10%. We analyse clusters in various dynamical states and mass ranges, finding that our method’s accuracy and precision are consistent. We verify the capabilities of our model by comparing it with the hydrostatic equilibrium technique, showing that it accurately recovers total mass profiles without any bias.