As long as you do it non-profit, distributing Pokemon fan games technically falls under fair use. However, Nintendo tends to see it as copyright infringement even when done non-profit, and will sometimes shut down fan games - even going so far as at one point forcing the Video Game Awards to throw away over half the votes cast for a particular category because those votes were cast for one of two fan games based on Nintendo properties.
Pokemon, as far as I understand it, is a property jointly-owned by three companies: Nintendo, Game Freak, and The Pokemon Company International (TPCi). Of these three, Nintendo is most protective of their stake in the matter, followed closely by TPCi. From what I hear, and I'm not sure how valid it is, after Nintendo shut down Pokemon Uranium, Masuda (who I'm assuming you know is a higher-up at Game Freak) wrote an apology letter to the developers because he knew that the game had not been intended as a copyright attack - showing that not always do the three companies agree.
That being said, in recent years, there have been only two Pokemon fangame shutdowns that I know of (technically three, but I don't know how long ago EVOAS was so I don't count it). Both of these games ended up basically falling onto Nintendo's radar due to circumstance. Uranium released right after Pokemon GO did, and a lot of gaming journals tried to take advantage of Pokemon hype by reporting on a fan game that they would have otherwise ignored. This gave Uranium a lot more momentum than anticipated, and as such, Nintendo noticed them. I don't know too much about Pokemon Prism, but I presume that something very similar happened due to it trying to release shorty after Sun and Moon - and the fact that they called themselves Prism, the same word as the category of the third legendary in the Azoth Trio, probably didn't help.
TL;DR: Making fan games falls on the border between legal and illegal, but as long as you don't get too popular you should be left alone.