Draw one rectangle and then draw a 2px line and center it in the rectangle.
Unless there's some reason you must have two separate rectangles.
(Assumption that all strokes are set to the default stroke alignment, which is centered on their respective paths)
Realistically, if two rectangles are actually butted against each other, there is no variation in the appearance of a stroke....
Yellow boxes are all the same width.... as are the strokes. However this is two separate rectangles.
The key may be to use Outline Mode (View > Outline) to ensure your rectangles actually do butt against each other. Outline mode can be an invaluable feature if you are trying to be precise in positioning. There is simply no way to be as accurate working strictly in Preview Mode.
Because if you have a gap or overlap between the rectangles:
.... and everything is stroked the same color, all you'll see in Preview Mode (View > Preview) is the apparent "thicker" stroke:
What actually happens is the two strokes overlap each other and are not aligned properly:
So, basically, this issue is ultimately because your two rectangles are not butting against each other.
Correctly aligned objects will have correctly aligned strokes which, when overlapping will not give the appearance of a thicker stroke.
You may also find it helpful to ensure
Use Preview Bounds is not checked in the Preferences. This will allow snapping to use actual object paths for snapping rather than their preview containing the stroke appearance.