Neem oil is used as a natural insecticide called Azadirachtin. This helps repel parasites including pinworm keeping in mind that pinworm adults crawl outside the anus at night to lay eggs. It also stops the eggs from sticking as it is an oil.
If you know or suspect your horse has pinworm then it's recommended that you spray neem oil liberally on and around the horse's anus, ideally at night, along with applying vaseline. This should be done for at least four days prior to and after worming your horse with a ivermetin-based product.
Neem oil is said to have additional benefits as well. It's supposed to repel midges while also being an excellent anti-inflammatory compound. It's also supposed to aid in the healing of sweet itch.