Trying to create a link in a custom module
#markup is used for content that has already been rendered. As the caller seems to be expecting a render array, you can just return it directly:

return $endpoint-&gt;toRenderable();