Unified first law of black hole dynamics and relativistic thermodynamics