in my early cacti growing days, I had a trichocereus Pachanoi, it was in a plastic pot which had holes on the bottom, when I would water the cacti, water would leak out of the holes onto the table, so I placed a wash-cloth under the pot to catch this water. A few weeks after, the top of the cactus turned into a black mush, as did a small pup.
...the washcloth under the pot had become moldy.
It may be counterintuitive to think that an issue at the top of the cactus could have its cause in the roots or soil, but all to often this is the case.
After removing the blackened sections of cactus and removing the moldy washcloth from under the pot, I proceeded to re-pot the cacti. I placed it in a clean pot with fresh, clean, well draining soil, and sure enough it recovered, and is thriving today.
This was a novice mistake, however, I'm glad that it taught me to be very mindful of having clean, well draining soil and clean potting in a clean environment, I am also mindful not to over-water, and to remove any potential sources of molds or other contaminants.
I'm not sure if this is the situation with your cacti, but figured I would explain what I did in a similar situation.
Try re-potting in a fresh clean pot, with fresh, clean, well-draining potting soil.
-eg