What Dmytro said is correct, Sitecore will only look at referenced items one level deep when publishing related items. What you need to do is have it also consider media items linked on those related items, then you'll catch the media items on your data sources. You can accomplish this if you override the logic that publishes the related items in the pipeline.
Take a look at the class Sitecore.Publishing.Pipelines.GetItemReferences.AddItemLinkReferences. You can reflect on this class and replace it in the pipeline with your own class that adds the logic to crawl the media items. For example, create a new class by copying what's in AddItemLinkReferences, then add this step when it's adding the linked items:
...
foreach (Item obj in itemLinkArray.Select(link => link.GetTargetItem()).Where(relatedItem => relatedItem != null))
{
list.AddRange(PublishQueue.GetParents(obj));
list.Add(obj);
// This will look at the item's links looking for media items.
list.AddRange(GetLinkedMediaItems(obj));
}
return list.Distinct(new ItemIdComparer());
}
Then add this method,
protected virtual List<Item> GetLinkedMediaItems(Item item)
{
List<Item> mediaList = new List<Item>();
ItemLink[] itemLinkArray = item.Links.GetValidLinks()
.Where(link => item.Database.Name.Equals(link.TargetDatabaseName, StringComparison.OrdinalIgnoreCase))
.ToArray();
foreach (ItemLink link in itemLinkArray)
{
try
{
Item target = link.GetTargetItem();
if (target == null || !target.Paths.IsMediaItem)
continue;
// add parent media items or folders
Item parent = target.Parent;
while(parent != null && parent.ID != ItemIDs.MediaLibraryRoot)
{
mediaList.Insert(0, parent);
parent = parent.Parent;
}
mediaList.Add(target);
}
catch (Exception ex)
{
Log.Error("Error publishing reference link related media items", ex, typeof(AddItemAndMediaLinkReferences));
}
}
return mediaList;
}
And the config to include it in your publish pipeline,
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<getItemReferences>
<processor type="Sitecore.SharedSource.Pipelines.Publish.AddItemAndMediaLinkReferences, Sitecore.SharedSource"
patch:instead="processor[@type='Sitecore.Publishing.Pipelines.GetItemReferences.AddItemLinkReferences, Sitecore.Kernel']"/>
</getItemReferences>
</pipelines>
</sitecore>
</configuration>
Your problem inspired me to write a blog post about it: http://www.chrissulham.com/publish-sitecore-media-items-on-referenced-datasources/