I guess it's not a bug as such - if your party and the spell occupy the same square at the same time then BOOM. Most grid-based games like this work in this way.
If you cast the spell after strafing so a wall is directly in front of you, then the spell will hit in the square in front of the wall, ie the one you're in. That also applies for gates which are rising, as I know to my cost.
Guys, you didn't read his post, he states it happens with going sideways and backwards - you're not in the same square as the spell. I've personally seen this myself too, both times it was with the 'ice shards' spell which is very obvious what tiles it's affecting, and like the OP I cast it and moved at the same time. The spell 'fired' from the original tile I was in, because I can see the ice effect shoot forwards from that tile, and I simultaneously take damage as though the spell had hit the tile I moved to.
Sorry. I was half asleep when I posted, and didn't make it clear that I was meaning as an explanation for the strafing issue (which might explain it as a separate issue if a similar explanation was found for the going backwards one).
BUMP. this happens to me a lot while I backstep enemies while trying to cast spells. Very strange glitch that you can damage yourself by running backwards and casting a spell at the same time :/