If you’re using a theme that still receives updates from someone/somewhere else, and you haven’t created a child theme for your site, then it it would be lost next time they provide an update. However, if you are using an old theme that hasn’t been touched in years, or are using a child theme, then you would be fine.
Alternatively, you could create a quick plugin to house your CMB2 code and that would be completely safe and separated from any theme updates, and still work the exact same as what you have now.
To make it a plugin, you’d just need to create a folder and a php file in the plugins directory, and then put this at the top, followed by all the same code you put in your functions.php file.
<?php
/*
* Plugin Name: napalmx37's CMB2 code
* Plugin URI: Plugin URI
* Description: CMB2 configuration.
* Version: 1.0.0
* Author: napalmx37
* Author URI:
* License: GPLv2
*/
Assuming no syntax errors occurred, you’d then be able to activate that plugin and be on your way.