It comes from the phrase "stuffed to the gills" which means "so full, you can't eat any more." This seems to have come from the fact that when you stuff a fish for cooking, you fill it all the way to the gills.
In the early 20th century, "stuffed to the gills" had morphed into "soused to the gills," which meant "as drunk as could be." By the 1940s, this had morphed into "doped to the gills," which meant "as stoned as could be."
"To the gills" made it to athletics by 1976, when The Sporting News said that an East German shot-putter was "pumped to the gills" with drugs. The title of the article has a strangely contemporary ring to it: "Steroids Called Best Friends for Olympians."