Not seeing this on CS6 or CC. Are you sure you have your gradient selected as foreground and background and not on the preset of black and white?
I do not think you even need two document open to see that Swatches swap when Layer Mask is targeted.
I do not think its a bug it is more like its working as designed. The swatch Colors inverse shades of gray when Layer mask is targeted. When layer content is targeted the swatches colors will be what the user set. When layer mask is targeted the swatch colors will be shades of gray and inverse of the set color like black will be white and white will be black
Swtich targets between Layer content and Layer Mask and watch forground and backgrownd swatches swap when Black and White....
On further testing I think the issue may not be directly related to layer masks at all.
Basically the issue is that the Gradient tool colors don't update to the 'default foreground/background colors' in cases where it seems that they should.
One example of such a case (as illustrated in the original post) is when the Gradient tool keeps the black/white color combo used for a layer mask in a previous document after switching to the current document where a non-masked layer is targeted and the default fg/bg colors have correctly reverted to white/white.
layer mask targeted in doc1 - notice synchronised Gradient and default fg/bg colors
after switching to non-masked layer in doc2, Gradient is still black/white although default fg/bg colors have reverted appropriately to white/white
Bug or not, it's something I wanted to point out as it seems inconsistent.