How do you teach a pet to a do spell on it own free will?
there are two ways. first is getting lucky and training your pet like a spritely or disarm/peirce. (may have missed some) second: is you specially breed the talents into a pet, like the amazing pets that you sometimes see in the arena.
You can't teach it. If the pet has a spell as one of it's talents then the pet decides when to use the spell. I believe however, that some spells have "triggers" that will prompt the pet into action. For instance, if the pet has a useless spell like storm shield, it is much more likely to cast the storm shield after you have been attacked by a storm spell. Or if your pet has Fireblade, it will wait until you attack at least once before casting it's fireblade for you; As if it wasn't sure you were in a battle and wanted that extra blade on meteor or Fire Dragon.
The one exception seems to be spritely which a pet will cast almost anytime even if you are at full health. I have seen spritely cast up to 4 or 5 times per battle by other players pets. In fact if other spells were cast as often as spritely then the other spells might even be useful.
first off your pet has to learn ability spritely ( may cast sprite ) may cast towe shield pierce etc. it does not just magically cast it without learning said in a comment above usually they have triggers sometimes it is randomness