I've never actually seen soldiers attack teammates or civilians myself. I've only seen them either hunker down, shoot enemies, or on one occasion a guy killed himself with a grenade by accident.
The reason it happened was because the target selection for Grenade throws has no restrictions on the Teams, meaning when a panicking soldier decides to throw a Grenade it selects any possible target at random, it can be an enemy, an XCOM unit or civillians. However considering that the Target selection for Aimed shots is specifically restricted so that both XCOM soldiers and Aliens do not target XCOM soldiers when panicking this likely is an oversight from an early development stage, since the Game originally also had a targetselection for aimed shots that had no restrictions, meaning both XCOM soldiers and aliens could target any unit that was in their line of sight, until it got changed.