The hardware itself isn't inherently illegal — the legal problem is what gets loaded onto it. A flash card used for homebrew applications you've written or for media playback sits in a very different position from one loaded with commercial ROMs, which is straightforward copyright infringement.
Retailers have faced legal action in several countries over distribution and the bundled software, so the picture varies by jurisdiction. The practical rule is simple: your own backups and homebrew are one thing, downloaded commercial games are another.