If @No Time To Play doesn't mind if I add a little more explanation.
Legally you should not use content that you do not have the permissions to use, I say permissions, because you can buy or license content.
Fangames aren't really a gray area, you don't legally have the right to use someone else's content without their permission.
If the company or individual who owns the copyright wants, they can cancel your game and you have no right to claim, no judge will ever agree with you, because legally it is not a gray area.
In reality, what happens is that these games tend to have so little diffusion that the owners do not find out and never make a claim. Other companies do allow the use of their content in fangames.
itch.io has a reactive policy, they upload the game and if someone complains, they block it.
If you make a game with content that you don't know where it came from or whose copyright belongs to someone else, you run the risk of having it canceled.
How to minimize that risk?
If you use content from big companies, make sure it's from companies that don't have a problem with fangames, like Capcom.
If you use Nintendo or Sega content, and your game goes viral, it will most likely end up being canceled ("SOR remake" for example).
Try not to use content that you don't know its origin, for example, you could use some graphics that you found on the internet, you don't know that they were taken from another indie game and one day, here in itcho, someone realizes that your game uses the same sprite as another game, place the claim and your game will be canceled, again, you are taking unnecessary risks.
If you don't want to take risks, ask for help from an artist or use only royalty-free content and respect the license of each resource.
For example, at https://freesound.org/ you have a lot of effects and most of them are CC, or they simply ask you to place them in the credits.