Hoping you are familiar with trigger making at least somewhat, here's what you could do.
You need two triggers, or maybe three depending. The first of which would be a trigger that detects any enemy units within a range of the caster, creates a dummy unit, has the dummy unit cast polymorph on a random unit within the range you specified.
The first trigger is for a) if it's an active spell like Voodoo where the hero actually has to click on the spell and it consumes mana then you need a 3rd trigger for when the spell is turned off. If it's b) an aura like Endurance Aura that requires no mana and is on forever, then you need to do this:
After the first trigger is on you need to make another that checks, say every second or half second to see if an enemy unit is within range of the caster, if so you need to repeat trigger 1 with the dummy unit.
Now, unfortunately, if it's an activeatable spell, then I don't remember how to check for when the spell is turned off, someone else will have to tell you that part.