I have only had this happen once and the pet wasn't bonded.
Last night I tamed a dwh, mounted it, took it to town. In town, I dismounted it to lore it again, so I could compare it to my other dwh's. A guard teleported in and whacked my dwh. Was a nice one.... was...
I think this is only happening with pets that have just been tamed. I'm not sure what precautions you can take to avoid it from happening, but I suspect spending an hour outside town with your pet would prevent this from happening.
I think the problem is caused by the pet being "flagged" for attacking an innocent (you) prior to taming. Then when you unmount from it in town, the npc's see it as having just committed a crime.
As far as I know, you don't have anything to worry about with your bonded pets.