You buy it from a website that carries it (not your typical big-name site) and you download the homebrew games for free from another website. As long as you only stick to homebrew or public domain stuff, it's legal.
http://nintendo-ds.dcemu.co.uk is probably the best site for homebrew and they have a bunch of other info about hardware and stuff.