Because Greenland likely agreed to it
It's called international law, trade agreements, treaties etc.
Well, Denmark would have been the one to agree.