Ultra-compact dwarf galaxies (UCDs) have similar properties as massive globular clusters or the nuclei of nucleated galaxies. Recent observations suggesting a high dark matter content and a steep spatial distribution within groups and clusters provide new clues as to their origins. We perform high-resolution N-body/smoothed particle hydrodynamics simulations designed to elucidate two possible formation mechanisms for these systems: the merging of globular clusters in the centre of a dark matter halo, or the massively stripped remnant of a nucleated galaxy. Both models produce density profiles as well as the half-light radii that can fit the observational constraints. However, we show that the first scenario results to UCDs that are underluminous and contain no dark matter. This is because the sinking process ejects most of the dark matter particles from the halo centre. Stripped nuclei give a more promising explanation, especially if the nuclei form via the sinking of gas, funnelled down inner galactic bars, since this process enhances the central dark matter content. Even when the entire disc is tidally stripped away, the nucleus stays intact and can remain dark matter dominated even after severe stripping. Total galaxy disruption beyond the nuclei only occurs on certain orbits and depends on the amount of dissipation during nuclei formation. By comparing the total disruption of cold dark matter subhaloes in a cluster potential, we demonstrate that this model also leads to the observed spatial distribution of UCDs which can be tested in more detail with larger data sets.