If granting military access means allowing someone to invade your enemy/rival, it's obviously beneficial.
Consider this absurd scenario: Denmark is at war with Sweden. Brandenburg is also (but separately) at war with Sweden, and wants to invade them through Denmark. But they can't, since Denmark won't allow them military access because Denmark considers Brandenburg a rival, and Denmark ends up losing the war because of that decision.
Consider this absurd scenario: Denmark is at war with Sweden. Brandenburg is also (but separately) at war with Sweden, and wants to invade them through Denmark. But they can't, since Denmark won't allow them military access because Denmark considers Brandenburg a rival, and Denmark ends up losing the war because of that decision.