Is it bad for headphones to be attached to magnets? Will it damage them and make the sound quality worse or something?
The basic functionality of a speaker (your headphones are small speakers) is this:
An electromagnet has a varying current applied to it. The varying current creates a change in the magnetic field and causes a reactive material to fluctuate (deform in proportion to the change in magnetic field). The fluctuation causes changes that are detected by your ears. Setting a magnet next to a speaker does not change the reactive material or the magnet in the speaker itself. This is because there is no applied current in the "other" magnet, and therefore no fluctuation in magnetic field. This causes no net change in the speaker (headphones). Now if you force similar polarities of two magnets together (N + N or S + S) you negate the two fields. Look up degaussing on the web for an explanation.
Short answer: There should be no negative effect from this behavior. Forcing the two similar polarities of the two magnets together may cause a decrease in the strength of the magnetic field in both magnets over time, decreasing the responsiveness of the speakers. You would have to force this behavior as two similar polarities will naturally repel each other.