Both methods are correct and won't have effect in performance or functionality of the code you put into the the plugin or
Any theme related code, like hooks and filters manipulating output of that theme only should be kept in
functions.php and other important custom code better be in a custom plugin.
Maintaining a custom plugin to hold all yourcustom code is rather a better idea than stuffing it into your
functions.php file. Benefits:
- If you're using a commercial or any third party theme and it gets updated, your code in
functions.php will be lost, this is in case you're not using a Child Theme.
- In case of theme change, you don't need to get into hassle of copy pasting the custom code to your new theme's
- Code will be organised and code maintenance will become easy.
- Code like registering CPTs and custom taxonomies is intended to stay despite of theme change, so it better be in a plugin so it stays functional even after theme change.
Other than these, every developer has their own reasons for keeping code in
functions.php or custom plugin.