Can too much sex or masturbation cause loss of muscle gains?

No. Sexual activities such as normal intercourse and normal masturbation have a large physical action component, as well as a psychological component. Physical action means using muscles to move various parts of one's body repetitively... which means he or she is exercising. The result is better muscle tone and strength in those muscles. That's why people go work out at the gym... to exercise muscles.
Here are some.... No definite answer could be drawn, but could be speculated as the process of reaching orgasm is a process of very high mental and physical drainage. So, it is conceivably to deduce that sex may consume some muscles mass, but this has not been well studied, As to "over"-sex, please peruse article on potential adverse effect of obsession in http://formefirst.com/eNewsletter05.html. All the best....