Pixels are weakly typed units. Just like 1
can be coerced into an integer, floating-point value, or string in a weakly typed language, a "pixel" is coerced into whatever unit makes sense in context.
If we were to more strongly type the unit, we'd probably have several:
pixel-width;
pixel-height;
pixel-diagonal; and
pixel-area.
As you correctly point out, if we assume that pixels are squares, then$$
\left[\text{pixel-area}\right] = {\left[\text{pixel-side}\right]}^2,
$$such that it'd make more sense to speak of square-pixels when discussing image size in terms of pixel-sides.
The thing's just that, if we're talking image size, then a "pixel" is meant to be coerced into a pixel-area, not a pixel-side.
Note: Pixels are units
A unit is literally anything we use to express measurements of some sort. Sure pixels are objects, but so are other units - there's no conflict there. For example, in the US, we still measure lengths in feet.
Object-defined units of measurement were the historical norm, so there's nothing unusual about pixels being object-defined units. Just, there're obvious shortcomings to such definitions, so in recent history standardization efforts have been made. For example, feet are now more formally defined than as a person's foot's length.
That said, the same is happening to the pixel unit:
A device-independent pixel (also: density-independent pixel, dip, dp) is a physical unit of measurement based on a coordinate system held by a computer and represents an abstraction of a pixel for use by an application that an underlying system then converts to physical pixels.
-"Device-independent pixel", Wikipedia