How to make my themes compatible with different WordPress versions?

It depends on the core functions you are using in the theme. Let’s say that you are using get_theme_file_uri which is introduced in WP 4.7(not released yet) instead of it’s counter parts get_theme_directory_uri. Your theme doesn’t support older versions if you don’t have any back compat functions.

Similarly every newer version of WordPress comes with new functions,API’s,classes,actions,filters. So if you are using newer functions the theme doesn’t support older versions of WP.