why you clear it
The goblin army is the gate on the Goblin Tinkerer. Beat it once and he appears bound somewhere in the caverns, and freeing him gives you reforging, the Tinkerer's Workshop for combining accessories, and Rocket Boots. That makes it the most useful pre-hardmode event by a wide margin, and it is worth forcing the moment you qualify rather than waiting for the roll to land.
when it turns up on its own
The check happens at dawn. It wants a broken Shadow Orb or Crimson Heart somewhere in the world, at least one player at 200 or more maximum health, and no other invasion running. Under those conditions your first army is a one in three chance each morning, so it usually arrives within a few in-game days of qualifying.
After the first clear the odds collapse to one in thirty in pre-hardmode and one in sixty in hardmode, which averages out to about one army per twelve hours of real playtime, then one per twenty four. If you want them faster, the Goblin Battle Standard is the answer. Goblin Scouts wander the outer thirds of the map and drop Tattered Cloth, which is the only ingredient you cannot buy or grow. Standards are cheap enough that most people keep a few spare.
how far you have to get
It is a kill counter, not a timer. Solo the target is 120 goblins, and every additional player above the 200 health line at the moment the event starts adds another forty. Not everything is worth one kill, so the table is worth a glance before you plan a multiplayer run. Progress is stored in the world, so dying costs you nothing and logging out costs you nothing either.
doors, and why they matter here
Goblin Peons do not open doors, they smash them. If the door belonged to the room holding your bed, your spawn point resets. If it belonged to an NPC's house, that NPC is suddenly homeless and can move out. Peons cannot break a door that is already open, so the standard preparation is a walk through the base beforehand leaving every door swinging. Blocking the frames works too if you would rather not have goblins strolling through the living room.
fighting it
Most of the roster walks in a straight line and dies to anything that pierces. Spears, flails and boomerangs pull far more weight here than a single-target weapon with better numbers. The Spiky Balls that Goblin Thieves drop are close to free damage, because the rest of the army will keep walking into them without ever reacting.
Two enemies break the pattern. Goblin Sorcerers blink around and throw fireballs, which punishes standing in one spot. Goblin Warlocks only exist in hardmode, and they will start appearing partway through an army that began in pre-hardmode if you trip hardmode mid-event. They fly fast, fire through walls and hurt on contact, which makes recovering your gear after a death on mediumcore genuinely painful.
where to stand
The army enters at one edge of the world and marches to the spawn point, taking somewhere between 35 and 70 seconds to arrive depending on world size. Goblins only appear near it, and you have to be within roughly 187 tiles horizontally and no deeper than about 67 tiles below the surface for that to include you. Once it has reached the center, standing near a town NPC also qualifies, though only about two thirds of spawns become goblins that way. A flat clearing at spawn with a couple of platform layers over it is the entire arena this event ever needs.

