How can an extension conditionally show (or hide) a block

If a block visibility depends on a config settings value then you can use an ifconfig expression in a layout file:

<referenceContainer name='form.buttons'>
	<block
		class='Dfe\Google\Block\Backend\Template'
		name='Dfe_Google_Backend_Buttons'
		template='buttons.phtml'
		after='adminhtml_auth_login_buttons'
		ifconfig='dfe_google/login/enable'
	/>
</referenceContainer>

You a visibility condition is more complex an can not be expressed with ifconfig then you can show / hide a block by overriding the \Magento\Framework\View\Element\AbstractBlock::toHtml() method.
If you return the empty string from the method then the block will not be shown.

<?php
namespace Dfe\Facebook\Block;
class Login extends \Magento\Framework\View\Element\Html\Link {
	/**
	 * @override
	 * @see \Magento\Framework\View\Element\Html\Link::toHtml()
	 * @return string
	 */
	public function toHtml() {return !rm_customer_logged_in() ? parent::toHtml() : '';}
}

The sample shows the block for anonymous visitors only by using the rm_customer_logged_in sample function which detects whether the visitor is authenticated or anonymous,

See also How to load JavaScript or stylesheet conditionally based on admin config settings