The spatial distribution of matter in clusters of galaxies is mainly determined by the dominant dark matter component; however, physical processes involving baryonic matter are able to modify it significantly. We analyse a set of 500 pc resolution cosmological simulations of a cluster of galaxies with mass comparable to Virgo, performed with the AMR code ramses. We compare the mass density profiles of the dark, stellar and gaseous matter components of the cluster that result from different assumptions for the subgrid baryonic physics and galaxy formation processes. First, the prediction of a gravity-only N-body simulation is compared to that of a hydrodynamical simulation with standard galaxy formation recipes, and then all results are compared to a hydrodynamical simulation which includes thermal active galactic nucleus (AGN) feedback from supermassive black holes (SMBHs). We find the usual effects of overcooling and adiabatic contraction in the run with standard galaxy formation physics, but very different results are found when implementing SMBHs and AGN feedback. Star formation is strongly quenched, producing lower stellar densities throughout the cluster, and much less cold gas is available for star formation at low redshifts. At redshift z= 0 we find a flat density core of radius 10 kpc in both the dark and stellar matter density profiles. We speculate on the possible formation mechanisms able to produce such cores and we conclude that they can be produced through the coupling of different processes: (I) dynamical friction from the decay of black hole orbits during galaxy mergers; (II) AGN-driven gas outflows producing fluctuations of the gravitational potential causing the removal of collisionless matter from the central region of the cluster; (III) adiabatic expansion in response to the slow expulsion of gas from the central region of the cluster during the quiescent mode of AGN activity.