Can a spellcaster counterspell a magical trap?
Yes, but only if 1) the magical trap duplicates a spell and 2)
he has readied the counterspell action to do so.
For example, a mere 1st-level wizard could counterspell
one of the burning hands traps detailed in the DMG, as long as
she had readied a counterspell action to do so. However, even a
20th-level wizard couldn’t counterspell a trap that simply
created a burst of fire without actually duplicating a specific
spell.