To simplify things, there are two ways to wire a light switch and a light:
Power=========Switch==(A)===Light
Power=========Light===(B)===Switch
(traditionally, but wiring standards have changed)
If the switch comes first, the cable coming from the switch (A) will provide switched power to whatever you want to put on it.
If the light comes first, the cable between the light and the switch (B) is called a "switch loop". If you open up that cable, it will have a white and black conductor so it looks like hot and neutral, but it's actually playing the role of only the hot. If you were to splice in a fan at position (B), the fan would complete the circuit, and it would run by pulling power through the light.
In most cases the light would also come on, but depending on the electrical characteristics of the light and the fan, only one of them might come on.
When the switch is turned on, it is what completes the circuit to the light, so the power no longer has a reason to run through the fan.
If the above seems true - you spliced into the cable between the light and switch - the only way to wire it correctly would be to run a cable from the light to the fan. The switch box most likely wouldn't have a neutral, so you can't run a new cable from there.