It's interesting and potentially disturbing all at the same time. I think we'd need similar apples to apples sales data for other games/franchises to more accurately say it was piracy that caused that, but really, that's a pretty damning number. You gotta keep in mind that not only did 3DS sales numbers skyrocket during the time between Pokemon X and Y, but Pokemon Go also came out the previous summer, and that must've definitely had an effect on Pokemon game and 3DS system sales.
However, perhaps another theory is that the 3DS game library matured and there was more to play, and so less people bought Sun and Moon? Let's look at the Switch. At launch and for a while after, sales of Breath of the Wild surpassed the amount of Switch systems even sold, but if you look at sales data now, Super Mario Odyssey and Mario Kart both outpaced Zelda, despite releasing later. I think it's rather obvious that Zelda was the system's crown jewel at launch, and a game that every Switch owner basically had to have. Later, when the system started getting a more diverse library of games, it seems that choice knocked down Breath of the Wild sales. Heck, it was even beat by the Wii U port of Mario Kart 8. Considering this, it's possible that Pokemon X and Y had a larger attach rate, so a higher percentage of 3DS owners bought into it. Then later, with more games to choose from, 3DS owners simply spent their money elsewhere and Pokemon sales stagnated.
At any rate, It's hard to tell anything from just one piece of data. This is just my speculations.