So I’m not sure what happened. Can you tell me how to avoid whatever is happening in the future? :(
That’s an aggressive, necrotrophic fungal infection of some kind. The plant might have been overwatered, damaged somehow or pests may have allowed the fungus to infect it. The plant wasn’t very healthy, it was stressed somehow, which made is susceptible to fungal infection. It may have been overwatered before you bought it. If it experienced extremes of temperature (too hot or too cold), then that could have allowed the fungus to infect it too. It’s hard to say for sure what happened, but the cactus wasn’t very healthy. The soil doesn’t look great and the root system is quite small, which could have contributed to the health of the plant.