This, with minor variations, is a common saying meaning that another person's misfortune is not (entirely) their fault. If conditions had been a bit different, it might have been you, and not them.

This most likely comes from John Bradford (1510(?)-1555), an English protestant martyr, who is quoted as saying "But for the grace of God, there goes John Bradford." whenever he saw criminals being led off to their execution.

There But For The Grace Of God I Go is also a song by Dorothy Wallace