you need to try this code.
For phtml file you need to used this code.
<?php
$customerror = $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();
$this->_messageManager->addError(__($customerror));
?>
For block file you need to do code like this.
class Yourclass
{
protected $cmsblock;
public function __construct(\Magento\Cms\Block\Block $cmsblock)
{
$this->cmsblock = $cmsblock;
}
public function Yourfunction()
{
$customerror = $this->cmsblock->setBlockId('block_identifier')->toHtml();
$this->_messageManager->addError(__($customerror));
}
}
Replace 'block_identifier'
with your block identifier.