Legal matters are tricky, and the less you know, the worse off you are.
Realistically, many fangames can be allowed to develop free from legal obstructions under fair use, on similar ways a song is covered or a parody of made.
On the other hand there are some loop holes to the already touchy relationship, that can be exploited, like putting the hammer for reasons of likeness, names, reused sprites or images and what have you.
Ultimately, it comes down to if you want to spend months fighting it in court with millions of dollars on your head.
Naturally, the answer is no.
Companies should be more like Sega, Capcom or Namco Bandai in that regard, not only do they not care, but they at times actively engage in the projects and the communities thereof.