When playing TF2 as a Soldier, I noticed that some of my rockets fired at the enemy exploded on the backs of teammates who were also focused on killing them. However, the rest of my rockets just clipped through my allies and made it to their intended targets. Why and how does this work?
Yes, but only in certain circumstances. With default settings, rockets will only pass through teammates that are very close to you. Once they get out of face range they will explode on teammates and deal splash damage to enemies. The close range exception saves you from having to worry about blowing yourself up if a teammate steps in front of your gun.
Those were probably server configs that allowed projectiles to pass through teammates. In vanilla TF2, rocket projectiles will never go through teammates and will explode upon contact with them.