I was considering asking this question on math stack exchange but decided not to because "first principles" seems like more of a physics thing.
I'm looking for a conceptual proof of the pythagorean theorem from first principles. Actually, it might be better to say the distance formula rather than the pythagorean theorem because I'm thinking about distances in three dimensions.
I don't find any of the usual proofs of the distance formula satisfying. There are a number of proofs from first principles in euclidean geometry but then I feel like I have to move triangles and squares around or break out proportions every time I use the distance formula. On the other hand there are a lot of conceptual proofs of the pythagorean theorem, e.g. using the dot product or the law of cosines, but each of these just pushes the question around. If I use the dot product to "prove" the pythagorean theorem I need to know why we use the dot product from first principles. If I use the law of cosines then I need to know why vectors that are $90^{\circ}$ to each other are perpendicular. I'm sure this sounds perverse so let me try to make what I'm looking for a bit more precise.
For me "understanding" a thing is always understanding it within a particular conceptual system. Within that system we have admissible intuitions and understanding is when those intuitions are matched with rigorous math. Those intuitions could be of the formal relations between various quantities and how we interpret that physically. So there are all these different ways to understand this stuff, but what I'm lacking is a way to understand them simultaneously. (--ok, I really tried here, and I know it is super confused but its not getting any better than this)
The distance formula is such an elementary and fundamental fact about our everyday experience that I feel like there must be some better way to understand it than "we can prove it and its mutually compatible with other concepts like inner products and angles and the math that relates them".
I've been wondering about this on and off ever since I learned about the dot product proof of the pythagorean theorem. At first I was more wondering why the the dot product lets us compute angles via $u \cdot v = \|u\| \|v\| \cos(\theta)$, and this still seems extraordinary to me, so I would want a way to understand the relation between inner products and angles from first principles too.
Right now my thinking is that from first principles (whatever first principles is) distance is a thing, rigid motions is a thing, distance is preserved by rigid motions, rigid motions includes translations, rotations, and reflections, so distance is translation invariant and respects scaling, so distance comes from a norm, then because the parallelogram law is so obviously true (not obvious to me at all), this norm comes from an inner product given by the polarization identity.
If I could understand why the parallelogram law is true from first principles then by the rest of the above I would have one of these nice conceptual systems from first principles through inner products, and that would include the pythagorean theorem.
But understanding why the parallelogram law is true seems at least as hard as the pythagorean theorem itself, since its essentially a more general form, so I'm going to settle with understanding how it can fail. I see two avenues for this. First there are various examples of norms where the parallelogram fails to hold, for example all of the $L^p$ spaces. Second, the pythagorean theorem, and presumably the parallelogram law, fail to hold in geometries with nonzero curvature.
I think this clarifies what I mean by "conceptual proof of the pythagorean theorem from first principles" so I think its reasonable to ask for approaches found in textbooks or expository papers to the pythagorean theorem / inner products / angles following a similar outline to what I gave above.
I'm not certain it will actually help clear up anything at all for you, but it's worth knowing that other folks before you have asked much the same thing, some of them with considerable profit from the exercise. The classic example of this is Riemann's "Inaugural Lecture," of which there is a translation near the start of Volume 3 of Spivak's Differential Geometry. A somewhat less understandable (!) translation is available here: https://www.maths.tcd.ie/pub/HistMath/People/Riemann/Geom/WKCGeom.html.
One question to ask yourself is "What are my first principles, and why?" Another is "Under which sets of first principles is the theorem true?" For the second, you've already observed that for curved spaces, it doesn't necessarily hold. So what axioms are you willing to use to define "not curved spaces"?
Hilbert's version of Euclid's Axioms is a pretty good start. Of course, they spend a lot of time talking about lines and intersections and angle measures, and the resulting proofs of the Pythagorean Theorem use things that seem apparently irrelevant, like squares constructed on the triangle sides, and translations/rotations in the plane, etc. But there's a reason for that: the Euclidean axioms are about as simple as you can make them, which necessarily means that it's quite some distance from the axioms to the more interesting theorems.
There's a related reason that has to do with philosophy and status and a bunch of other things, and I sadly can't recall where I first read this: Euclid and friends were not much interested in numbers and measurements --- those were things that concerned tradesmen and shopkeepers rather than philosophers. As philosophers, they thought of ratios as the far more central concept. Things like algebra were ... well, they were irrelevant to some degree. So to the Greeks, the claim is not that $a^2 + b^2 = c^2$, but instead that if you erect a square on each leg of the right triangle, and another square on the hypotenuse, then the "sum" of the first two squares is the third square, where "sum" here literally meant some kind of addition of areas (done via cutting and pasting, without too much concern about whether this was indeed well-defined) rather than about sums of numbers.
A modern view says that there's an area-measurement function, and that the whole greek argument boils down to (1)it being additive on disjoint sets or something, (2) it being invariant under congruence transformations, and to one key lemma: the area-function, applied to a triangle of base $b$ and height $h$, yields $(1/2)b h$ [or an equally simple lemma about rectangles]. But to the greek mathematicians, "measurement" wasn't the kind of central idea it is now.
At least some historians of mathematics believe that tradespeople had known Pythagoras's theorem long before it was proved as a geometric theorem --- it was the sort of thing that made it easy to lay out the foundations of a house in a rectangle rather than a somewhat skewed parallelogram!
I'm rambling here, and I apologize. At the heart of things, I suggest you think hard about what you believe are your "first principles", and why. Only then can you get a really satisfactory answer to your question.