Where to put code for coding Custom Post Types?

I think that this choice really depends on the project. If a post type is intrinsically linked to the theme. Maybe your theme will have a js and css bundle that includes post type features. In this case it is better to define it immediately in this one. But it really depends on the project and how the code is organized. There is no “THE right method”.

But if the custom post type brings new features that may potentially need to be deleted (for example: an event list on a site). It is better to define them in a plugin or mu-plugin.