You're targeting a location whenever you aren't targeting an object or a creature
When you make an attack you declare its target. While some attacks may specify they only work with specific types of target, others are variable and the decision is made when the attack is declared.
You can declare an attack as targeting a location when the other two options (creature or object) do not apply.
Examples of targeting a location include, but are not limited to:
When you believe something in the space is hidden or invisible.
If you believe there is an invisible creature next to you, you may declare an attack on the empty space to see if you hit something. It wouldn't make sense any other way since you, as a player and in character, shouldn't know if something is occupying the space and you need to be able to declare an attack. Of course, the GM knows whether this is actually an attack on the creature or not.
When you attack a target that you can’t see, you have disadvantage on the attack roll. This is true whether you’re guessing the target’s location or you’re targeting a creature you can hear but not see. If the target isn’t in the location you targeted, you automatically miss, but the GM typically just says that the attack missed, not whether you guessed the target’s location correctly. - Unseen Attackers and Targets, 5e SRD - Emphasis mine
You're either guessing a target's location or you're targeting a creature you've somehow otherwise detected.
When you want to throw an item, like a net or a bomb, into a specific square.
The DM may have you roll an attack against a location if you want to throw/shoot something, with accuracy, into a specific square or space. Perhaps near a creature or object, but not directly at them. PerhapsFor example: you want to throw a dagger past someone's ear:. You aren't attacking them, you're attacking the space next to them.
If you want to embed your throwing axe at someone's feet or throw something next to a barrel, you're targeting a location.
In these types or situations, you wouldn't be rolling against an AC but a DC set by the DM.