We study the origin of the diffuse stellar component (DSC) in 117 galaxy clusters extracted from a cosmological hydrodynamical simulation. We identify all galaxies present in the simulated clusters at 17 output redshifts, and then build the family trees for all the z=0 cluster galaxies. Then for each diffuse star particle identified at z=0, we look for the galaxy to which it once belonged at an earlier redshift, thus linking the presence of the diffuse stellar component to the galaxy formation history. The main results of our analysis are: (i) On average, half of the DSC star particles comes from galaxies associated with the family tree of the most massive galaxy (BCG), one quarter comes from the family trees of other massive galaxies, and the remaining quarter from dissolved galaxies. I.e., the formation of the DSC is parallel to the build-up of the BCG and other massive galaxies. (ii) Most DSC star particles become unbound during mergers in the formation history of the BGCs and of other massive galaxies, independent of cluster mass. Our results suggest that the tidal stripping mechanism is responsible only for a minor fraction of the DSC. (iii) At cluster radii larger than 250 kpc/h, the DSC fraction from the BCG is reduced and the largest contribution comes from the other massive galaxies; in the cluster outskirts, galaxies of all masses contribute to the DSC. (iv) The DSC does not have a preferred redshift of formation: however, most DSC stars are unbound at z<1. (v) The amount of DSC stars at z=0 does not corre late strongly with the global dynamical history of clusters, and increases weakly with cluster mass.