You need a capture card to do so, which means you need a modified 3DS.
The one that I know of is a guy named Loopy who lives in the States. He can only do this with the 3DS, as 3DS XL/ 2DS are not supported yet.
Here is his site: http://3dscapture.com/
There used to be an option to buy a new 3DS and the capture board together from him, but the 3DS is now being phased out and replaced by the 3DS XL, so you either need to buy a 3DS second hand or wait until he makes capture boards for the 3DS XL.
Here is a Reddit forum discussing how Loopy also created a 2DS Gamecube controller.
Additionally, on your surfing of the web you may find someone named Katsukitty who also offers the same service. I've heard from a lets play Youtuber that they do a really shoddy job on their capture boards, which break easily (just over a month; Katsukitty only warrant their capture board modifications for a month). Loopy has actually been repairing Katsukitty's handiwork, which shows you how bad they must be if their competition is willing to repair their work because it gives their whole trade a bad name.