#markup is replacing colon in <gcse:search... tag with space
Use an inline template:

  return [
    '#type' =&gt; 'inline_template',
    '#template' =&gt; '&lt;gcse:search queryParameterName="query" resultsUrl="{{ url }}"&gt;&lt;/gcse:search&gt;',
    '#context' =&gt; [
      'url' =&gt; Url::fromRoute('cn.search', [], ['absolute' =&gt; TRUE]),
    ],
  ];