Polluted white dwarfs are detected through spectroscopic analysis. By examining the light emitted by these stars, astrophysicists can identify the presence of various elements based on their unique spectral lines. The unexpected presence of heavier elements indicates that these white dwarfs must have accreted material from their surroundings.