Hello Gniagnia
You could say that if the previous test doesn't work, it must be 'whomever'. Or you could see if the sentence 'tests positively' for 'whomever' by substituting 'the person whom':
1. It belongs to whomever it belongs to.
Substitute 'the person whom':
2. It belongs to the person whom it belongs to.
Which =
3. It belongs to the person to whom it belongs.
Which is fine; so 'whomever' is fine.
Or another example, without a preposition:
4. Send this letter to whomever it may concern.
Substitute 'the person whom':
5. Send this letter to the person whom it may concern.
Again, fine: 'whom' is the object of 'concern'.
MrP