If you pre-compile the layout template, you should be able to set the Layout directly by casting the template to TemplateBase. If you later specify the Layout in the template markup, this will override the value in the code as you require when the template executes.
ITemplateService templateService = ...;
// Ensure layout template is cached with layoutCacheName
templateService.GetTemplate(layoutAsString, model, layoutCacheName);
ITemplate template = templateService.GetTemplate(templateAsString, model, templateCacheName);
var templateBase = template as TemplateBase;
if (templateBase != null) templateBase.Layout = layoutCacheName;