How to set the title for the current page programmatically?

Use the Magento\Framework\View\Page\Title::set() method: