Ok, I gave a misleading answer and I think I need to address it. Space-time has a different metric than space, and Pythagorean theorem works differently. In familiar 3D, the metric is ##dr^2 = dx^2 + dy^2 + dz^2## so Pythagorean theorem is as above.
But in 4D space time, time has an opposite sign to space, so the corresponding metric is ##ds^2 = -dt^2 + dx^2 + dy^2 + dz^2## or ##ds^2 = dt^2 - dx^2 - dy^2 - dz^2## depending on the convention you adopt.
So you can rewrite ##E^2 = (mc^2)^2 + (pc)^2## as
##(mc^2)^2 = E^2 - (pc)^2##
##(mc^2)^2 = E^2 - (p_xc)^2 - (p_yc)^2 - (p_zc)^2##
The invariant mass "m" is the 4D length of the energy and momentum 4-vector. But length is calculated using something like the Pythagorean theorem but with negative sign in front of the momentum. This is a result of the negative sign in the metric. This is clearer if you drop all the c constants from the equation.
##m^2 = E^2 - p_x^2 - p_y^2 - p_z^2##
You can drop c if you measure length and time in compatible units. If you measure time in seconds, you should measure length in light-seconds, and then you can set c = 1 light-second/second and then make it go away.