Let's take gambling. As seen in these answers here and here, gambling is a vice. No two ways about it. But there is an entire sukta in Atharva Veda dedicated to success in gambling as seen here
I have also understood from Somaka's story in Mahabharata that human sacrifice , though it gives intended benefits, is still considered a sinful act.
My question is why mantras and rituals exist for activities that are not as per dharma . If doing the right karma is the dharma then why even have such mantras and rituals in first place ?
Note : Not looking for answers that try to justify it on the basis that it was not sinful initially but became sinful over a period of time because of evolving society.