The short answer is "no".
The less short answer is "yes, unless someone tells you to stop".
The long answer is "it is ultimately at the discretion of the rights holder whether or not to enforce their copyright against you, but they will never not have that right, regardless of whether you are selling the product. You will need to look into whether the thing you are making a fan game of has rights holders who strongly enforce their rights, or are more permissive, and whether this permissiveness depends on the fan game being not for profit. Making a fan game is never 100% safe, since even if a rights holder has a policy of permissiveness, they still can retract that at any time, or even apply it on an individual basis, since it is not a legally binding concept. It is not a good idea to sink effort into a fan game because most rights holders are not permissive, and will send a cease and desist with zero warning."