Most probably the anal lining has been lacerated (injured) during anal sex. That's why you are having mucus.
The sperm of your husband is not left inside; it has come out with the stool.
I suggest not to have anal sex for some time and to avoid constipation
. The hard stool you are experiencing indicate for constipation.
If no improvement, contact proctologist
for further evaluation.
All the best!