Weird period spotting

Sydney
I usually don't spot at all on my own, but it's been happening every time I masturbate for two months and only then. I'm on the pill and my periods have been somewhat irregular, could it connected to that? Please help.