Why not build a particle accelerator on ground level? What is the shallowest feasible depth to build one?

The main reason for going underground is that the earth above provides some radiation shielding. An accelerator where everything is working properly is (outside the beam pipe) a relatively low-radiation environment. However if you have a steering or focusing magnet malfunction, so that the beam spills out of the pipe, you can briefly generate lots of prompt radiation.

The amount of shielding that you need depends on the energy of the accelerator. For example,

  • The 12 GeV electron accelerator at JLab is seven or eight meters underground --- just a couple of flights of stairs.

  • The 1 GeV proton machine at the Spallation Neutron Source is actually at ground level, but there's an earthen berm above it.

  • The (shuttered) 25 MV tandem accelerator at ORNL actually did most of its acceleration in a tower aboveground, and the various beam pathways are in a single above-ground building.

The lower the energy of your accelerator is, the less you need earthen shielding for safety reasons.

Another answer points out that background-limited experiments go underground to reduce cosmic ray backgrounds. This is a reason to put your detectors underground, but not necessarily a reason to put your accelerator underground.

Particle accelerator facilities are complicated beasts and they have several parts. Two subsets of thee systems have different reasons for being underground.

  • The beam generation, acceleration, steering and focusing mechanisms generate ionizing radiation (by bremsstrahlung and beam scraping mostly). Some parts of some system generate a lot of radiation. These parts need shielding to protect people and a pile of dirt is a cheap way to get that shielding.

    The civil construction costs are usually lowest if you dig a shallow tunnel and then pile the dirt so obtained back over the top, and this is a common pattern for accelerators build in areas with relatively low population density.

    Currently running example: CEBAF at Jefferson Lab in Newport News, Virginia, USA.

  • The detector system used to do science with the beams detect all kinds of radiation and large detectors get many signals from cosmic rays. These detector systems can benefit from being put underground where the overburden reduces the cosmic ray background, though this is mostly of interest in neutrino physics where even with intense beams the rate at the detector is quite low.

    Unfortunately the cosmic rays consist largely of muons (because the atmosphere is enough shielding to reduce the contribution of less penetrating components) and have a spectrum that goes up to very high energies, so it takes a lot of overburden to significantly reduce the background.

    Currently running example: LHC at CERN in Geneva, Switzerland.

As a matter of universal policy facilities with beam intense enough to cut through the vacuum components of the accelerator if badly mis-steered (which has happened—briefly because the machine doesn't operate when the vacuum is compromised—at more than one lab) don't run the machine with people in the enclosure. This isn't really from worry that people will actually get hit by the beam, but because the radiation generated by the running apparatus represents a severe threat to human health.

It's because of shielding, according to the official CERN website:

Why is the LHC underground?

The LHC uses the tunnel that was built to house CERN’s previous large accelerator, the LEP, which was dismantled in 2000. Digging an underground tunnel proved to be the best option for a 27-km machine, since it’s cheaper than acquiring land to build on at the surface and the impact on the landscape is minimised. In addition, the Earth’s crust provides good shielding against radiation.

Also because building such large ring-shaped devices underground is actually often cheaper than building on the surface, since you do not need to acquire a huge amount of land.