Order posts by taxonomy count

this topic might help you. By default args of WP_Query – this is impossible.

I don’t think you can do that directly. Although you can save terms
count for each post in a custom meta field (on post publish) and then
in your query define sort by that meta field. Or while running your
query, you can save terms count along with posts ids in another array,
then sort them by count and print posts. Second one will consume more
resources so I would recommend first method.

SELECT p.ID,COUNT(*) count FROM wp_term_relationships r, wp_posts p,
wp_term_taxonomy x WHERE r.object_id = p.ID AND p.post_type=”post”
AND r.term_taxonomy_id = x.term_taxonomy_id AND x.taxonomy =
‘post_tag’ GROUP BY object_id ORDER BY count;

you can’t do it directly, you need a filter and a CASE in the orderby eg