In a Cartesian two dimensional plot, the distance d between two points `(x_1,y_1)` and `(x_2,y_2)` is `d=sqrt((x_2-x_1)^2+(y_2-y_1)^2)`
Conside the two points in a coordinate system.
(1) If the x coordinates are the same the points lie on a vertical line. The distance between points on a line is `|y_2-y_1|=sqrt((y_2-y_1)^2)` which is the distance formula where the difference of the x values is zero.
(2) Similarly, if the y coordinates are the same the points lie on a horizontal line and the distance is `d=|x_2-x_1|=sqrt((x_2-x_1)^2)`
(3) If both of the x and y coordinates differ then you can connect the two points with a line segment. Without loss of generality assume that `x_1<x_2,y_1<y_2` . Label `(x_1,y_1)=A,(x_2,y_2)=B`
Draw a horizontal line through `x_1` and drop a perpendicular line from `x_2` to the horizontal line. Label the intersection C. ABC is a right triangle (the created segments are perpendicular.) By the Pythagorean theorem `AC^2+BC^2=AB^2` where d=AB.
`AC=x_2-x_1` and `BC=y_2-y_1` . Substituting we get
`d=sqrt((x_2-x_1)^2+(y_2-y_1)^2)` which is the distance formula.
In three dimensions we can use the generalized distance formula and repeated uses of the Pythagorean theorem.
So the Pythagorean theorem can be used to find the distance between two points in a 2-dimensional real coordinate system if both the x and y values differ. Otherwise, there is no triangle. The distance formula can be used in any case of two points in a real 2-dimensional coordinate system.