As with anything to do with international politics and agreements its rarely simple.
The 2% seems a reasonable attempt to try and find a way to balance across a huge range of diverse economies.
But it is a broad brush stroke. For example the US is likely to always be spending such an amount, or more, due in part to it's non NATO commitments around the world.
The 2% can be further distorted by countries having different allocations made from military budgets.
Defense research, coastguard services, intelligence services etc. The more you count as defence spending the easier it is to reach the 2%.
For example some countries regard the coastguard service as a military force, others as more akin to a hybrid police/border/rescue service.
It's always a problem when using a broad measure across a large range of diverse entities that it's sometimes comparing apples with oranges and tomatoes.
The 2% is a credible attempt to find a balance, but it's not perfect.