Sharks and whales have them in the middle of their body, so why not planes?
With sea creatures the dorsal fin acts as a keel providing the actual sideways force during the turn. They remain level while turning.
Planes on the other hand bank to turn where the sideways force is provided by the lift of the wings.
To provide yaw stability the vertical stabilizer should be as far from the center of mass as possible. They are not in front because that would be unstable as the minor deviation from straight ahead would increase the force into the deviation rather than provide a force to counteract it.
The vertical stabilizer is for "stability". By having it aft of the center of gravity, it will generate a side force that will correct out any undesired yaw.
Try throwing a paper airplane or a dart backwards, and watch how it flips around due to this stabilizing force to have the stabilizer in the rear.
To add to other answers, vertical stabilizers also have control surfaces on them, and in order to maximize the effect of those control surfaces, you have to have them as far out from the center of horizontal rotation as possible.
Why not in front:
Stabilizers create drag. Drag is pulling backwards. When they are in the back, that's a natural resting point for them and thus they actually try to keep plane stable in one direction. Move them to the front and you would get a force that constantly tries to turn you butt-first :)
Example you can try at home:
Imagine a swinging door. The closer you move the door handle to the hinges, the more force is required to open the door. same applies to the airplane. If you place the rudder in the middle it will mostly push plane to the side instead of turning it.