Some cities and communities advise against flushing dead goldfish or other pet fish down the toilet because it goes into the sewer treatment plant.
But flushing a pet fish down your toilet is not illegal and even if it were illegal to flush a dead pet fish down the toilet there would be no way for the city to know who did it.
The police or even the city can't tell who flushed what down the toilet and all that will happen is that the fish travels down your sewer pipes and out into the city sewer system.
Then the fish eventually arrives at the sewer treatment plant where they screen things out of it and then the fish if caught in the screening gets removed and thrown in the trash.
Or the fish continues on out and goes into a lake or river.
I've always just flushed dead fish down the toilet and it's never been a problem.