get_the_category()get_the_terms() で取得したカテゴリーやタームをID順に変更する方法。
いずれも functions.php へ追記することで、ID順で取得できるようになります。

get_the_category()

カテゴリーの取得順をID順に変更する

function category__sort_by_id($categories) {
    usort($categories, '_usort_terms_by_ID');
    return $categories;
}
add_filter('get_the_categories', 'category__sort_by_id');

get_the_terms()

タームの取得順をID順に変更する

function term__sort_by_id( $terms ) {
    usort( $terms, '_usort_terms_by_ID');
    return $terms;
}
add_filter( 'get_the_terms', 'term__sort_by_id' );

参考

_usort_terms_by_ID() | Function | WordPress Developer Resources

Reference | WordPress Developer Resources