Capping-layer-induced magnetic coupling in a two-dimensional nanostructured system