The short answer to anything regarding the use of anyone else’s games, characters, etc. is that they have all the power in the world to stop you IF they want to. Technically even drawing a fan art picture of say Super Mario is illegal.
So it all depends on who the owner of the rights is and how hard they want to crack down on fan creations. Nintendo has been quite harsh with what it allows and what it doesn’t in the past, so I personally would not want to venture into the realm of Nintendo fan games. The general rule is that companies don’t tend to act upon anything they don’t think will negatively affect their current, future or potential plans. So drawing that picture of Mario isn’t really going to do anything bad to them, but making a game (which is what their company mainly does) is obviously seen as a potential threat, so they’ll most likely try to stop it even if it’s free and you make nothing with it.
The proper way to go about any kind of fan game making, is to contact the copyright holders and notify them of what you want to do, ask if it’s okay and wait for a response. You will in virtually all cases be rejected outright. But trying to be secretive about your project and having them find out later and try to sue you, is in my view a worse option than being denied permission before you spend countless hours working on it.
PS. Game mechanics are not copyrighted. So you can make a similar game as long as you avoid any direct connections to copyrighted things.