I could be wrong but I don't think it's stopping down to achieve greater dof as such as that surely is a decision for the photographer to make. I think it's more the physics of the thing. The actual size of the aperture doesn't change but the lens sends focus distance information to the camera and the camera then displays the relative aperture for that distance. I believe that Nikons do this but Canons don't. I've no idea what other makes do.
I've only ever had 2 macro lenses, one in Canon fit and the one I have now which is completely manual so I've never seen the reported aperture change with distance in the VF.
There's a relatively easy to read piece here with further links you can follow.
https://photo.stackexchange.com/questions/99848/can-i-force-the-aperture-to-stay-open-on-macro-lens
"So from those equations, you can see that the effective aperture is equal to the real aperture (the focal length of the lens divided by the entrance pupil diameter)
only when the lens is focused at infinity. At infinity focus (or even just very large subject distances, such that
do ≫ ƒ), the magnification is basically zero, so the effective aperture
E equals
N."