How can astronomers use light spectroscopy to measure the composition of different planets when they can't directly image the planet because the star that they are orbiting is so much bigger and brighter than they are?
When an exoplanet transits in front of a star it blocks a fraction of the starlight that is given roughly by the ratio of the exoplanet radius to the stellar radius squared (i.e. the ratio of the projected areas).
The effective exoplanetary radius is then defined as the radius out to which the planet is opaque to the starlight attempting to "pass through it" on the way to us.
However, if the exoplanet has an atmosphere, then the edge of its occulting disk is is "fuzzy" and some light may be able to pass through its atmosphere on the way to us. The extent to which this happens will depend on the wavelength of the starlight and the composition of the exoplanet atmosphere.
In the image below (from https://casa.colorado.edu/~desert/GMOS-Survey.html) the exoplanet has a larger effective radius at blue wavelengths and this results i a larger transit depth at those wavelengths.
As an example, consider an exoplanet which has an extended atmosphere that contains lots of sodium atoms. If you observe the transit through a filter (or with a spectrograph) at the wavelength of the prominent "sodium D lines" (589 nm) then the effective radius of the exoplanet (including its atmosphere which will be opaque to photons at this wavelength) and hence the transit depth will be larger than at wavelengths either side of 589nm.
Thus by measuring the transit depth as a function of wavelength you are effectively performing transmission spectroscopy of the exoplanet atmosphere. These measurements along with a model of the physical conditions in the atmosphere (temperature and pressure) lead to an estimate of the chemical abundances.
When a planet is detected using the transit method, the passing of the planet in front of the star causes the star's luminosity to decrease by a little bit, and this phenomenon repeats itself every time the planet revolves back around its star. If the planet has an atmosphere, some of the light from the star first passes through that atmosphere before reaching our telescopes. Different particles in the atmosphere will preferentially absorb light of different wavelengths, so we can infer the composition of the planet's atmosphere by the periodic decrease in light detected from the star at various combinations of wavelengths.
It is also possible that some of the star's light reflects off of the planet, so the different wavelengths having different fractions of their light being reflected will lead to differential amounts of light reaching our telescopes. All of these are rather small fluctuations, which should give you some idea of the precision capabilities of modern telescopes!
There's a detailed example with real data here.