Preheat oven to 350°F (175°C).
Remove giblets from one (3 1/2- to 5-pound) whole chicken, rinse the bird inside and out, and pat dry. Tie the legs together with kitchen string.
Rub all over with 1/4 cup olive oil, 2 1/2 teaspoons sea salt, 1/4 teaspoon freshly ground black pepper, and 2 tablespoons fresh thyme leaves. Set the chicken aside for 1 hour to allow it to come to room temperature.
In a large cast-iron casserole, Dutch oven, or roasting pan, over medium-low heat, warm the second 1/4 cup olive oil. Add the 12 garlic cloves and 12 shallots or small onions, and cook until golden, about 10 minutes. Remove from the heat and nestle the chicken in the casserole dish, breast side up. Baste chicken all over with pan juices until well covered. Roast, uncovered, for 1 hour.
Pour the lemon juice over the shallots and garlic, avoiding the chicken. Baste with pan juices and sprinkle with half of the lemon zest.
Increase oven temperature to 425°F (220°C).
Continue roasting the chicken, uncovered, until an instant-read thermometer reads 165°F (74°C) when inserted into the thickest part of the thigh, and the skin is crisp and golden, 15 to 30 minutes more. Sprinkle with the remaining lemon zest. Let the chicken rest 15 minutes, then carve and serve, with the roasted garlic and shallots on the side, if desired.