How to align mesh parts? Suppose I have a mesh containing, among other things, two cubes of different sizes, both oriented so that the main axes of these cubes are parallel to the world axes.

How can I align these cubes so that the top planes are at the same z coordinate, leaving other coordinates unchanged?

One way to do it is to separate these cubes into two different objects, and to align these, but the original object contains a lot more than the two cubes, so it needs to be reconstructed after the alignment, which is too much effort.
Use Snapping.
Select the vertices you want to move.
Enable snapping (magnet icon) and set it to Snap to Vertices.
In a lateral Orthographic view move the vertices you want to align.

Other tools to be aware of:
Scaling to zero.
Select all of the vertces and scale to $0$ on the axis you need.
In this example all of the vertices are scaled on the z axis, this is done pressing SZ$0$:

For a more precise alignment, copy the coordinates of a vertex in a given axis, and make the selected vertices be at such coordinates using the Item &gt; Transform tab.
You can set the coordinates to global.

To copy and paste values, just move the cursor over to the value you want to copy and press Ctrl+C to copy and
Ctrl+V to paste